问题描述:

截图类似如下:


在做马甲应用(多变体APP)的时候,由于只配置了不同的
applicationId
和相应的代码目录,并没有对
ContentProvider
和项目中的第三方库等配置做修改,就出现了这个错误。一般都是由于两个APP的清单文件中的
provider
authorities
是一样的导致的。
另一个原因就是一些第三方库(如极光),也需要进行各个变体的配置,若是相同则也会出现此类错误。 解决方案:
provider${applicationId}
<provider
     android:name="android.support.v4.content.FileProvider"
     android:authorities="${applicationId}.fileprovider"
     android:exported="false"
     android:grantUriPermissions="true">
         <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
</provider>

2、针对第三方库的配置进行修改:

receiverJPUSH_PKGNAME
  • AndroidMainifest.xml
<receiver android:name="com.xuansa.bigu.receiver.JPushReceiver">
  <intent-filter>
      <action android:name="cn.jpush.android.intent.REGISTRATION" />
      <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
      <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
      <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
      <action android:name="cn.jpush.android.intent.CONNECTION" />
      <category android:name="${JPUSH_PKGNAME}" />
  </intent-filter>
</receiver>
  • build.gradle
productFlavors {
    v1 {    //变体1
        versionCode 1
        versionName "1.1.1"
        applicationId "com.test.v1"
        if (applicationId.endsWith('.debug')) { //debug
            manifestPlaceholders = [
                    JPUSH_APPKEY: "xxx",  //极光APPid
                    JPUSH_PKGNAME: applicationId  //可直接引用
            ]
        } else {    //release
            manifestPlaceholders = [
                    JPUSH_APPKEY: "xxx",  //极光APPid
                    JPUSH_PKGNAME: applicationId  //可直接引用
            ]
        }
    }
    v2 {    //变体2
        versionCode 2
        versionName "2.2.2"
        applicationId "com.test.v2"
        if (applicationId.endsWith('.debug')) { //debug
            manifestPlaceholders = [
                    JPUSH_APPKEY: "xxx",  //极光APPid
                    JPUSH_PKGNAME: applicationId  //可直接引用
            ]
        } else {    //release
            manifestPlaceholders = [
                    JPUSH_APPKEY: "xxx",  //极光APPid
                    JPUSH_PKGNAME: applicationId  //可直接引用
            ]
        }
    }
}

需要注意:

相同签名,不同包名的APP是可以同时安装的。但不能有指定的唯一的标识。

参考资料: