【问题标题】:Android Gradle Build Variants - applicationId not recognized by Google UploadAndroid Gradle Build Variants - Google Upload 无法识别 applicationId
【发布时间】:2016-04-12 21:49:37
【问题描述】:

我刚刚开始将我的第一个 Beta 版应用部署到 Google 的 Play 管理中心开发者网站。我最初的 APK 上传很好,但我需要支持多种环境,所以我正在尝试实现构建变体。

感谢这个 url:http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename,我理解了 PackageName 和 ApplicationId 之间的区别,并且我已经相应地实现了我的 AndroidManifest.xml 和 build.gradle。

我可以创建具有 ABI 特定和通用的签名 APK,但是当我尝试上传与之前相同的通用时,我收到错误: "你的包名必须是 com.myapp"

这是我的 AndroidManifest.xml 中的标头:

<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
}

我已点击链接并在 AndroidManifest.xml 和 build.gradle(defaultConfig 和 ProductFlavors)的相应部分中指定了 PackageName 和 ApplicationId。

关于为什么无法识别 packageName 或如何测试 APK(即命令行、验证器等)的任何想法

问候, -J

【问题讨论】:

    标签: android gradle android-productflavors


    【解决方案1】:

    在使用 gradle 工具进行构建时,AndroidManifest.xml 的内容实际上与实际的包名称无关。

    当你在 build.gradle 中这样说时:

    applicationIdSuffix ".release"
    

    这有效地从 defaultConfig 中获取您的 applicationId 并将“.release”添加到它的末尾。这就是打包在最终 APK 中的内容。因此,您的发布 APK 的包 ID 为“com.myapp.release”。

    【讨论】:

    • 谢谢我发现也使用这个:stackoverflow.com/questions/6289149/… 注意:我必须将 aapt 添加到我的 PATH 下(mac):~/Library/Android/sdk/build-tools/version/我尝试了aapt dump badging <path-to-apk> | grep package:\ name,它没有产生任何结果,所以 tiaapt dump badging <path-to-apk> 我发现后缀导致了这个问题。有没有办法将后缀添加到文件名而不是包名? -J
    • 看起来就是这样:versionNameSuffix "-myrelease" stackoverflow.com/questions/19172565/… 感谢您的快速回答!非常感谢。
    猜你喜欢
    • 2021-08-26
    • 2013-11-08
    • 1970-01-01
    • 2017-03-06
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 2015-01-13
    相关资源
    最近更新 更多