Android Gradle 构建变体 - Google 上传无法识别 applicationId
Android Gradle Build Variants - applicationId not recognized by Google Upload
我刚刚开始将我的第一个测试版应用程序部署到 Google 的 Play 控制台开发者网站。我的初始 APK 上传正常,但我需要支持多种环境,因此我正在尝试实施构建变体。
由于这个 url:http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename,我理解了 PackageName 和 ApplicationId 之间的区别,并且我已经相应地实现了我的 AndroidManifest.xml 和 build.gradle。
我可以创建一个带有特定 ABI 和通用 ABI 的签名 APK,但是当我尝试上传与之前相同的通用 ABI 时,我收到错误:
"Your package name must be com.myapp"
这是我AndroidManifest.xml中的header:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp">
这是我的 build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 21
targetSdkVersion 22
versionName "12-APR-2016"
versionCode 12042016
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/NOTICE'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
debug {
buildConfigField "String", "SERVER_URL", "\"https://dev.myapp.com/?action=\""
applicationIdSuffix ".debug"
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
release {
buildConfigField "String", "SERVER_URL", "\"https://release.myapp.com/?action=\""
applicationIdSuffix ".release"
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
productFlavors {
x86 {
applicationId "com.myapp"
versionCode Integer.parseInt("6" + defaultConfig.versionCode)
ndk {
abiFilter "x86"
}
}
mips {
applicationId "com.myapp"
versionCode Integer.parseInt("4" + defaultConfig.versionCode)
ndk {
abiFilter "mips"
}
}
armv7 {
applicationId "com.myapp"
versionCode Integer.parseInt("2" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi-v7a"
}
}
arm {
applicationId "com.myapp"
versionCode Integer.parseInt("1" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi"
}
}
}
splits {
abi {
enable true // enable ABI split feature to create one APK per ABI
universalApk true //generate an additional APK that targets all the ABIs
}
}
// map for the version code
project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile group: 'com.android.support', name: 'appcompat-v7', version: '23+'
//omitted for brevity
}
我已按照 link 并在适当的部分 AndroidManifest.xml 和 build.gradle(defaultConfig 和 ProductFlavors)中指定了 PackageName 和 ApplicationId。
关于为什么无法识别 packageName 或如何测试 APK(即命令行、验证器等)的任何想法
此致,
-J
AndroidManifest.xml 的内容实际上与使用 gradle 工具进行构建时的实际包名称无关。
当你在 build.gradle 中这样说时:
applicationIdSuffix ".release"
这实际上是从 defaultConfig 中获取您的 applicationId 并在其末尾添加“.release”。这就是打包在最终 APK 中的内容。因此,您发布的 APK 的包 ID 为 "com.myapp.release".
我刚刚开始将我的第一个测试版应用程序部署到 Google 的 Play 控制台开发者网站。我的初始 APK 上传正常,但我需要支持多种环境,因此我正在尝试实施构建变体。
由于这个 url:http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename,我理解了 PackageName 和 ApplicationId 之间的区别,并且我已经相应地实现了我的 AndroidManifest.xml 和 build.gradle。
我可以创建一个带有特定 ABI 和通用 ABI 的签名 APK,但是当我尝试上传与之前相同的通用 ABI 时,我收到错误: "Your package name must be com.myapp"
这是我AndroidManifest.xml中的header:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp">
这是我的 build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 21
targetSdkVersion 22
versionName "12-APR-2016"
versionCode 12042016
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/NOTICE'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
debug {
buildConfigField "String", "SERVER_URL", "\"https://dev.myapp.com/?action=\""
applicationIdSuffix ".debug"
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
release {
buildConfigField "String", "SERVER_URL", "\"https://release.myapp.com/?action=\""
applicationIdSuffix ".release"
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
productFlavors {
x86 {
applicationId "com.myapp"
versionCode Integer.parseInt("6" + defaultConfig.versionCode)
ndk {
abiFilter "x86"
}
}
mips {
applicationId "com.myapp"
versionCode Integer.parseInt("4" + defaultConfig.versionCode)
ndk {
abiFilter "mips"
}
}
armv7 {
applicationId "com.myapp"
versionCode Integer.parseInt("2" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi-v7a"
}
}
arm {
applicationId "com.myapp"
versionCode Integer.parseInt("1" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi"
}
}
}
splits {
abi {
enable true // enable ABI split feature to create one APK per ABI
universalApk true //generate an additional APK that targets all the ABIs
}
}
// map for the version code
project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile group: 'com.android.support', name: 'appcompat-v7', version: '23+'
//omitted for brevity
}
我已按照 link 并在适当的部分 AndroidManifest.xml 和 build.gradle(defaultConfig 和 ProductFlavors)中指定了 PackageName 和 ApplicationId。
关于为什么无法识别 packageName 或如何测试 APK(即命令行、验证器等)的任何想法
此致, -J
AndroidManifest.xml 的内容实际上与使用 gradle 工具进行构建时的实际包名称无关。
当你在 build.gradle 中这样说时:
applicationIdSuffix ".release"
这实际上是从 defaultConfig 中获取您的 applicationId 并在其末尾添加“.release”。这就是打包在最终 APK 中的内容。因此,您发布的 APK 的包 ID 为 "com.myapp.release".