Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applicationId manifest placeholder for multiple build flavors not working

I am modifying current android project so it can be installed on same device for multiple flavors and build configs.

build.gradle:

{
    // ...
    defaultConfig {
        applicationId "com.myapp"
        manifestPlaceholders = [
            manifestApplicationId: "${applicationId}",
            onesignal_app_id: "xxxx",
            onesignal_google_project_number: "xxxx"
        ]
    // ...
    }

    productFlavors {
        production {
            applicationId "com.myapp"
            // ...
        }

        dev {
            applicationId "com.myapp.dev"
            // ...
        }

        // ...
    }

    buildTypes {
        release {
            // ...
        }

        debug {
            applicationIdSuffix ".debug"
            // ...
        }
    }

    // ...
}

AndroidManifest.xml:

<manifest ... >
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <permission
    android:name="${applicationId}.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />      
    <!-- ... -->

    <receiver
        android:name="com.onesignal.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>

    <!-- ... -->
</manifest>

When I compile both debug and release version of the same flavor, I got error message:

...

INSTALL_FAILED_DUPLICATE_PERMISSION

perm=com.myapp.permission.C2D_MESSAGE

pkg=com.myapp.dev

...

manifestApplicationId placeholder came from AndroidManifest.xml on OneSignal library as instructed on https://documentation.onesignal.com/docs/android-sdk-setup

Anybody have a clue how to fix this problem? Thank you.

like image 655
Wellsen Avatar asked Sep 01 '16 18:09

Wellsen


People also ask

What is manifest placeholder?

xml file in the directory structure. Android Manifest usually contains pre-defined or static information which is then used to run the app. However, Android toolchain provides customization by allowing you to specify dynamic information through variable declaration, generally referred as Android Manifest placeholders.

How do I merge manifest files on Android?

If you want to apply the merge rule markers to only a specific imported library, add the tools:selector attribute with the library package name. For example, with the following manifest, the remove merge rule is applied only when the lower-priority manifest file is from the com. example. lib1 library.

When would you use product flavor in your build setup?

123 let's go Simply put, a product flavor is a variant of your app. It is very useful when you want to create multiple versions of your app. This means you can generate different versions or variants of your app using a single codebase.

How do I add Flavours to my Android?

Now you have three different flavors of the same application to change the build variant, Android Studio uses select Build > select Build Variant in the menu bar (or click Build Variants within the windows bar), then select a build variant from the menu.


1 Answers

OneSignal requires the manifestPlaceholders key manifestApplicationId to be set to your applicationId (AKA your package name).

This can be done by setting it in your buildTypes like the following.

buildTypes {
   debug {
      defaultConfig {
         manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                 onesignal_app_id               : "11111111-1111-1111-1111-111111111111",
                                 onesignal_google_project_number: "111111111"]
       }
   }

   release {
      defaultConfig {
         manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                 onesignal_app_id               : "22222222-2222-2222-2222-222222222222",
                                 onesignal_google_project_number: "222222222"]
      }
   }
}

Update 1: OneSignal-Android 3.3.0 no longer requires manifestApplicationId.

Update 2: OneSignal-Android 4.0.0 no longer requires any manifestPlaceholders values. Instead OneSignal.setAppId(ONESIGNAL_APP_ID) needs to be called at runtime.

like image 64
jkasten Avatar answered Sep 22 '22 03:09

jkasten