Search Unity

AAR ${applicationId} Field Populated w/ Wrong/Stale Value

Discussion in 'Android' started by kromenak, Jul 30, 2019.

  1. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    Hello, I have some build scripts that run and change the application bundle identifier depending on the version of our game that is being built. For example, one build might be "com.company.title.dev" and the other might be "com.company.title"

    When building an APK, the AAR files I'm using in my project, particularly Facebook, have some instances where the ${applicationId} field in the manifest is replaced with the app's bundle identifier during the build process. The exact instance where this happens is the FacebookInitProvider, which can be seen here: https://github.com/facebook/faceboo...er/facebook-core/src/main/AndroidManifest.xml

    The value filled in for ${applicationId} during the build process does not seem to accurately reflect the bundle identifier that I'm using.

    For example, if I build for "com.company.title.dev," it populates the manifest with "com.company.title.dev.FacebookInitProvider". If I build for "com.company.title" it STILL uses "com.company.title.dev.FacebookInitProvider".

    This is a problem because Android doesn't let you install two applications with the same Provider name. So, this effectively blocks me from being able to install dev and prod builds at the same time on Android.

    I'm wondering where Unity is pulling this value from and whether it is cached anywhere that also needs to be changed? My build script updates the ProjectSettings bundle ID before performing the build process, but Unity does not seem to see this when it's time to fill in the ${applicationId} field.

    I thought maybe Unity might be caching this in the "Temp" folder or in some gradle location, but I haven't found this yet. Any one else encountered this, or know what's going on?
     
  2. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,965
    This sounds something wrong. The applicationId substitution is not something done by unity but by gradle system. Have a look over here.

    Temp folder has gradleOut folder once you export apk. Try checking that folder if anything wrong in build.gradle file. You can build from there directly to give a test "gradlew build"
     
  3. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    In the gradleOut folder, the only time the wrong bundle identifier appears is at "gradleOut/build/intermediates/merged_manifests/release/processReleaseManifest/merged/AndroidManifest.xml". It appears in no other file in that folder or any subfolder.

    The android/defaultConfig/applicationId field in "build.gradle" is also set correctly.

    Even if I execute gradle again manually (or use Android Studio), the issue persists!

    Perhaps this provides a clue - I found the file "manifest-merger-release-report.txt" located at "gradleOut/build/outputs/logs". It contains these lines:

    provider#com.facebook.internal.FacebookInitProvider
    ADDED from [:com.facebook.android.facebook-core-4.37.0:] /Users/NAME/.gradle/caches/transforms-1/files-1.1/com.facebook.android.facebook-core-4.37.0.aar/7f57d204d6b63293940476cbbb709d6b/AndroidManifest.xml:33:5-173
    android:authorities
    ADDED from [:com.facebook.android.facebook-core-4.37.0:] /Users/NAME/.gradle/caches/transforms-1/files-1.1/com.facebook.android.facebook-core-4.37.0.aar/7f57d204d6b63293940476cbbb709d6b/AndroidManifest.xml:33:73-145
    android:exported
    ADDED from [:com.facebook.android.facebook-core-4.37.0:] /Users/NAME/.gradle/caches/transforms-1/files-1.1/com.facebook.android.facebook-core-4.37.0.aar/7f57d204d6b63293940476cbbb709d6b/AndroidManifest.xml:33:146-170
    android:name
    ADDED from [:com.facebook.android.facebook-core-4.37.0:] /Users/NAME/.gradle/caches/transforms-1/files-1.1/com.facebook.android.facebook-core-4.37.0.aar/7f57d204d6b63293940476cbbb709d6b/AndroidManifest.xml:33:15-72


    Sure enough, the gradle cache contains a manifest that already has the (wrong) substitution cached. But deleting the entire gradle cache plus the entire "gradleOut/build" folder STILL generates a manifest with the wrong applicationId!

    In any case...this seems to be some sort of gradle cache issue rather than something Unity is doing wrong. I'll have to keep fiddling with it...
     
    Last edited: Jul 30, 2019
  4. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    Ugh, think I figured it out - the AAR files in my actual Assets folder somehow got the ${applicationId} field filled in with one of the bundle IDs. Overwriting the AAR with an original one (from the Facebook SDK) seems to resolve the problem.

    I'm not sure HOW that happened in the first place - perhaps an older version of Unity or maybe some setting on the Google JAR Resolver that has since been disabled. Anyway - I think that'll fix it! (facepalm)
     
    jhughes2112 likes this.
  5. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,965
    Glad you found it!
     
  6. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    178
    Exact same sequence of events for me. It is an issue if you have Google Play Resolver with "Explode AARs" checked, I think. Because the bundle ids are stored in AAR files (zipped), you can't grep for ${applicationId} being replaced with bundle ids.

    If you get this kind of error:
    adb: failed to install game2.apk: Failure [INSTALL_FAILED_CONFLICTING_PROVIDER: Scanning Failed.: Can't install because provider name com.company.game1.FacebookInitProvider (in package com.company.game2) is already used by com.company.game1]

    Specifically, the facebook-wrapper-android and facebook-core .AAR files are the ones that get tainted. Easiest to nuke all the Firebase and Facebook stuff and reinstall after disabling the checkboxes.
     
    tim-bluenose and kromenak like this.