我是Android Studio的新手,在设备上运行调试版本工作正常,但是在应用程序购买测试(显然要发布)我需要使用普通密钥签名的发布版本.我可以使用Build - > Generate signed APK制作APK,但是包名似乎不正确.这是我的构建文件:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 9
testPackageName "com.company.common.common"
testInstrumentationRunner "android.common.InstrumentationTestRunner"
}
signingConfigs {
releaseConfig {
storeFile file("filname")
storePassword "password"
keyAlias "alias"
keyPassword "password"
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.releaseConfig
}
}
productFlavors {
Flavor1 {
packageName "com.company.test"
}
}
}
dependencies {
// some dependencies
}
Run Code Online (Sandbox Code Playgroud)
请注意在flavor中重写的包名称.那味道没有明显; 唯一的清单是在main下,并指定一个com.company.common包.如果我使用Android创建com.company.test APK并将其安装在设备上,然后从Android Studio生成APK并安装它,我最终会在设备上安装两个应用程序而不是第二个替换第一个应用程序.这表明包名称不同,我假设因为Android Studio正在生成一个带有com.company.common包的APK.不知道怎么验证这一点.
当我刚刚构建项目时,我得到一个调试APK但没有发布APK.如何获得具有正确包名的发布APK?我刚从Android …
我的问题类似于这个没有答案的问题:
我正在尝试将一堆所有共享相同代码库的Android项目(当然还有不同的软件包名称)转换为一个多味道的Android Studio/gradle项目.之前的每个应用程序都将成为新项目的构建风格.我从Eclipse导出并导入到Android Studio,并将其构建.
我的问题是,当我将com.company.appname的源代码重构为com.company.common时,带有"appname"风格,现在R文件仍然是com.company.appname.R.我无法从公共代码中引用它,因为下一个风格将包含com.company.otherappname.R.
这是我的build.gradle,如果这有用的话.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 9
testPackageName "com.company.common.common"
testInstrumentationRunner "android.common.InstrumentationTestRunner"
}
buildTypes {
debug {
packageNameSuffix ".debug"
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
AppName {
packageName "com.company.appname"
}
}
}
dependencies {
some libraries and stuff
}
Run Code Online (Sandbox Code Playgroud)
我可以粘贴清单,如果这会有所帮助.我可以使用反射来破解解决方案,但这很讨厌并且在引用资源时放弃了所有编译时的安全性,我想避免这种情况.唯一的其他解决方案是不从任何公共代码引用R类?