我在模块的 build.gradle
中有以下产品风格productFlavors {
pro {
applicationId "com.icounttimer.android"
}
free {
applicationId "com.icounttimer.android.free"
}
}
我的app模块的包结构是:
src/main/java/com/icounttimer/android/MainActivity.java
构建 pro-debug.apk 正确显示启动画面。但是, free-debug.apk 不会显示启动画面。
将“免费”风格的applicationId更改为'com.icounttimer.android'可解决此问题。但是当使用不同的applicationId时,不会显示启动画面。
环境:
CordovaLib:v3.6.3
Android Studio 1.0 RC4
此行为的原因是什么以及如何解决此问题?
答案 0 :(得分:2)
我找到的原因如下:
通过build.gradle更改 applicationId ,更改应用的包名称。
请注意,它与应用的包结构不同,在不同的构建版本中保持不变。
在这种情况下,应用程序包结构是不变的:src / main / java / com / icounttimer / android / MainActivity.java
通过代码潜水,我发现 CordovaActivity.java (CordovaLib的一部分)中的showSplashScreen()方法获得如下资源:
this.splashscreen = getResources().getIdentifier(splash, "drawable", getClass().getPackage().getName());
getIdentifier(...)方法的第三个参数是app的包名。
getClass().getPackage().getName()
根据包结构获取pkgName,无论它是哪种构建变体,它总是返回'com.icounttimer.android'。
要解决此问题,请将以下内容替换为CordovaActivity.java中的两个:
this.getPackageName() //returns the name of the application pkg which is the applicationId