Android project with a set of code package multiple APK, solve Installation failed with message INSTALL_FAILED_CONFLICTING_PROVIDER.

 

demand:

APK packaged with a plurality of codes, and can be mounted on the same phone 

Problems encountered:

When installed on the same phone will prompt an error:

Installation failed with message INSTALL_FAILED_CONFLICTING_PROVIDER.

 

The problem can be resolved is not a problem, is a valuable problem-solving ideas, this article would like to record my solution process. . . . . .

 

Packing configuration steps using a plurality of codes APK:

In fact, the Internet has a lot of introduction, here briefly summarize

1. In the app's file add the following code build.gradle

android {
    ...

    //创建一个APP维度
    flavorDimensions "APP"

    //多项目打包配置
    productFlavors {
        //项目例子1
        example1 {
            dimension "APP"
            applicationId "com.example.a"
            resValue "string", "app_name", "应用名称1"//应用名称
            manifestPlaceholders = [
                    app_icon: "@mipmap/ic_launcher1"//桌面图标
            ]
        }

        //项目例子2
        example2 {
            dimension "APP"
            applicationId "com.example.b"
            resValue "string", "app_name", "应用名称2"//应用名称
            manifestPlaceholders = [
                    app_icon: "@mipmap/ic_launcher2"//桌面图标
            ]
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

note:

If you are in the app strings.xml file also defines app_name, compile time will be a problem, because the above code resValue "string", "app_name", "application name 1" after the operation, AS will automatically generate the @ string / app_name , so there will be two app_name, so we want to remove the app strings.xml compiler will be normal.

2. Modify AndroidManifest.xml file

<application
        android:allowBackup="true"
        // 注意啦,这里改为${app_icon}
        android:icon="${app_icon}"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
           ...
</application>

 Packaging and signature APK

 

 Select the corresponding item packaged ok, so break out the example1 and example2 is only two different functions exactly the same icons and names of the two projects

problem:

When you have a project using provider, two applications installed on the same phone may prompt Installation failed with message INSTALL_FAILED_CONFLICTING_PROVIDER. Error

the reason:

Authorities provider uniquely identifies the tag, the installation fails because there are two provider use the same Authorities App

Solution:

Global search authorities, the death of the original configuration to write a reference gradle parameters to configure, for example:

With $ {applicationId} instead of the original package name written death

Advanced issues:

I began to do more operations but still prompted Installation failed with message INSTALL_FAILED_CONFLICTING_PROVIDER. Error, puzzling, global search provider, make sure that all configurations are changed over, it is still not

Explore:

Thinking: sure there are other places with the provider and can not be searched, possibly some third-party platform code;

Validation: add the following code to test in any Java file

StringBuffer sb = new StringBuffer();
        List<ProviderInfo> providerInfos = getApplicationContext().getPackageManager().queryContentProviders(null, 0, 0);
        for (int i = 0; i < providerInfos.size(); i++) {
            sb.append("i: " + i + " " + providerInfos.get(i).toString() + "---" + providerInfos.get(i).authority + "\n");
        }
        Log.e(TAG, "provide: " + sb);

Print more than one hundred provider of information, not specific log posted out, according to "com.example" search, because I ran a example2 project, found that there are two local authority include "com.example.a" word, right should be "com.example.b", namely:

i: 43 ContentProviderInfo{name=com.example.a.DownloadProvider className=cn.jpush.android.service.DownloadProvider}---com.example.a.DownloadProvider 和 i: 177 ContentProviderInfo{name=com.example.a.DataProvider className=cn.jpush.android.service.DataProvider}---com.example.a.DataProvider

See className, obviously Aurora push service, so it should be Aurora SDK configuration problems,

Examination revealed:

defaultConfig {
        applicationId "com.example.a"
        minSdkVersion 18
        targetSdkVersion 27
        multiDexEnabled true
        
        manifestPlaceholders = [
                JPUSH_PKGNAME: applicationId,
                JPUSH_APPKEY : "xxx", //JPush上注册的包名对应的appkey.
                JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
        ]
    }

applicationId here "com.example.a" is the default configuration, the latter will be based on the actual project modifications productFlavors inside, but because the configuration according to the project were not behind the reconfiguration of Aurora parameters, resulting in Aurora is the default configuration has been used, also is JPUSH_PKGNAME: applicationId of applicationId has been com.example.a

modify:

The Aurora moved following configuration parameters SDK

android {
    ...

    //创建一个APP维度
    flavorDimensions "APP"

    //多项目打包配置
    productFlavors {
        //项目例子1
        example1 {
            dimension "APP"
            applicationId "com.example.a"
            resValue "string", "app_name", "应用名称1"//应用名称
            manifestPlaceholders = [
                    app_icon: "@mipmap/ic_launcher1"//桌面图标
                    JPUSH_PKGNAME: applicationId,
                    JPUSH_APPKEY : "xxx", //JPush上注册的包名对应的appkey.
                    JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
            ]
        }

        //项目例子2
        example2 {
            dimension "APP"
            applicationId "com.example.b"
            resValue "string", "app_name", "应用名称2"//应用名称
            manifestPlaceholders = [
                    app_icon: "@mipmap/ic_launcher2"//桌面图标
                    JPUSH_PKGNAME: applicationId,
                    JPUSH_APPKEY : "xxx", //JPush上注册的包名对应的appkey.
                    JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
            ]
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

The defaultConfig Lane manifestPlaceholders = [] to remove

Rerun done. . . . . .

other:

1, since the break out of the APK package name is not the same, so to be useful, according to some third-party platform SDK package name registration will need to configure sub-item

2, pictures and other resources required to show different content depending on the project, you can create a corresponding project folder under the src directory, then create a corresponding resource directory, which would have a lot of online search tutorial

 

Released four original articles · won praise 3 · Views 3980

Guess you like

Origin blog.csdn.net/qq_24834241/article/details/82455681