2

I just started deploying my first beta app to Google's Play Console developer site. My initial APK uploaded fine but I need to support multiple environments so I am trying to implement build variants.

I understand the difference between PackageName and ApplicationId thanks to this url: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename and I've implemented my AndroidManifest.xml and build.gradle accordingly.

I can create a signed APK with ABI specific as well as universal but when I try to upload the same universal as I did prior I receive the error: "Your package name must be com.myapp"

This is the header in my AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp">

This is my 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
}

I've followed the link and specified the PackageName and ApplicationId in the appropriate sections AndroidManifest.xml and build.gradle (defaultConfig and ProductFlavors).

Any ideas as to why the packageName is not recognized or how I can test the APK (i.e. command line, validator, etc.)

Regards, -J

JT_Dylan
  • 133
  • 4
  • 15

1 Answers1

2

The contents of AndroidManifest.xml actually have no bearing on the actual package name when doing a build with gradle tools.

When you say this in your build.gradle:

applicationIdSuffix ".release"

That effectively takes your applicationId from defaultConfig and adds ".release" to the end of it. That's what gets packaged in the final APK. So your release APK has a package id of "com.myapp.release".

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks I found that also using this: http://stackoverflow.com/questions/6289149/read-the-package-name-of-an-android-apk Note: I had to add aapt to my PATH which is under (mac): ~/Library/Android/sdk/build-tools/version/aapt I tried `aapt dump badging | grep package:\ name` which produced nothing so ti`aapt dump badging ` and I found the suffix was causing the issue. Is there a way to add the suffix to the file name but not package name? -J – JT_Dylan Apr 12 '16 at 22:40
  • looks like this is it: versionNameSuffix "-myrelease" http://stackoverflow.com/questions/19172565/how-append-date-build-to-versionnamesuffix-on-gradle Thanks for the quick answer! Much appreciated. – JT_Dylan Apr 12 '16 at 22:45