这是针对 JVM 应用程序的。
我正在创建一个属性文件,其中包含要在应用程序运行时使用的版本。我在基础项目中编写了这个任务build.gradle.kts:
allprojects {
//...
tasks.register("createVersionPropertiesFile") {
group = "build"
doLast {
val resourcesDir = File("$buildDir/resources/main").apply { mkdirs() }
val resource = File(resourcesDir, "version.properties")
resource.writeText("version=${project.version}")
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我独立运行此任务,它会按我的预期创建文件。
为了在构建期间运行任务,我将其放入应用程序模块中build.gradle.kts:
tasks.processResources {
dependsOn += tasks["createVersionPropertiesFile"]
}
Run Code Online (Sandbox Code Playgroud)
然而,在构建过程中,资源目录实际上被删除而不是创建(或者如果是的话,它会在构建完成之前再次被删除)。因此,应用程序运行时找不到资源。
如何设置此任务在构建过程的适当阶段运行?
我知道另一种策略是在源代码的实际资源目录中创建资源文件,但我不想用这个自动生成的文件弄脏签入的源代码。我希望它只是构建的一部分。
我正在使用我在另一个堆栈溢出问题中提供的着色器来渲染我的灰度屏幕:
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
public class GrayscaleShader {
static String vertexShader = "attribute vec4 a_position;\n" +
"attribute vec4 a_color;\n" +
"attribute vec2 a_texCoord0;\n" +
"\n" +
"uniform mat4 u_projTrans;\n" +
"\n" +
"varying vec4 v_color;\n" +
"varying vec2 v_texCoords;\n" +
"\n" +
"void main() {\n" +
" v_color = a_color;\n" +
" v_texCoords = a_texCoord0;\n" +
" gl_Position = u_projTrans * a_position;\n" +
"}";
static String fragmentShader = "#ifdef GL_ES\n" +
" precision mediump float;\n" +
"#endif\n" +
"\n" +
"varying …Run Code Online (Sandbox Code Playgroud) 我正在更改方法内的全局变量值并尝试稍后返回它。
在 FetchData.kt(被调用的类)
var homeFeed: HomeFeed? = null // the variable that needs to be changed
fun execute() {
val client = OkHttpClient()
val url =
"..."
val request = Request.Builder().url(url).build()
val res = client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
override fun onResponse(call: Call, response: Response) {
val ch = response?.body?.string()
val gson = GsonBuilder().create()
homeFeed= gson.fromJson(ch, HomeFeed::class.java) // where the change happens
}
})
}
fun GetData(): HomeFeed? {
return …Run Code Online (Sandbox Code Playgroud) 我有一个有很多活动的应用程序.我在清单中设置了这个:
<uses-sdk android:minSdkVersion="4" targetSdkVersion="11"/>
Run Code Online (Sandbox Code Playgroud)
我还设置了v11风格,以便活动将全部使用v11 +上的Holo主题.
问题是我的所有活动都在系统栏上显示遗留菜单按钮.我的菜单(我在其中使用onCreateOptionsMenu)的活动同时显示了旧菜单按钮和操作栏溢出菜单按钮.按传统按钮可展开屏幕右上角的菜单.
在我不使用onCreateOptionsMenu的活动中,仍有一个遗留按钮不执行任何操作.
我无法弄清楚发生了什么.Hackborn写道,targetSdkVersion是控制是否显示遗留按钮的唯一因素:链接
编辑:澄清问题的描述.
有人告诉我,simple_one_for_one对聊天应用程序非常有用,因为每个聊天客户端都是一个服务器进程(gen_server).这是正确的吗?
我想知道为什么我们需要它?为什么不创建一个中心服务器(gen_server)来处理所有聊天客户端通信?因为聊天客户端的数量可能非常大,所以只有一台服务器无法快速处理,导致系统速度变慢?
我认为创建像simple_one_for_one这样的服务器太多可能会占用过多的系统资源.我是一个新的OTP人,所以我真的需要解释这一点.
I have an Activity layout that surrounds the fragment container in a CoordinatorLayout. When switching destinations, I want to hide the FAB and dismiss the SnackBar if either is currently displayed, and let the destination Fragment reshow the FAB if it needs to in its onViewCreated(). This is consistent with the Material Design guidelines that say the FAB should visibly disappear and reappear when you switch destinations.
So I did this:
navController.addOnDestinationChangedListener { _, navDestination, _ ->
binding.floatingActionButton.apply { …Run Code Online (Sandbox Code Playgroud) 这是我的代码风格(重置之前)
CommUtil.showCAlertDialog(
act = this,
msg = getString(R.string.network_error_app_fake_msg),
dialogFinishType = DialogFinishType.APP_PROCESS_KILL)
return
Run Code Online (Sandbox Code Playgroud)
但是当我重置计算机并下载 Android Studio 时,请像这样设置我的代码样式
CommUtil.showCAlertDialog(act = this, msg = getString(R.string.network_error_app_fake_msg), dialogFinishType = DialogFinishType.APP_PROCESS_KILL)
return
Run Code Online (Sandbox Code Playgroud)
我应该设置哪些选项才能返回到以前的代码风格?
android ×4
kotlin ×2
android-architecture-navigation ×1
erlang ×1
erlang-otp ×1
gen-server ×1
gradle ×1
java ×1
jvm ×1
libgdx ×1