Android Gradle: install all build types on one device

How can I configure my project to be able to install the debug version along with the release version when using GCM, ContentProvider, AccountType? (without flavoring)

I keep getting errors like: INSTALL_FAILED_CONFLICTING_PROVIDER or INSTALL_FAILED_DUPLICATE_PERMISSION

+4
source share
1 answer

Installing apug debug and apk release on the same device is complicated if you use only build types and not flavors ( Why Build types and not flavors )

( ), , applicationIdSuffix build type applicationId, flavors

  • GCM

applicationIdSuffix, , BuildConfigField resValue Gradle.

, , ​​ ( aosp tracker) abortOnError false, .

build.gradle

project.ext {
    defaultApplicationId = "com.myapp.package"
}
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId defaultApplicationId

        manifestPlaceholders = [ applicationIdWithSuffix: "${applicationId}" ]

        buildConfigField "String", "ACCOUNT_TYPE", "\"${applicationId}\""
        buildConfigField "String", "AUTHORITY", "\"${applicationId}.provider\""

        resValue "string", "account_type", "${applicationId}"
        resValue "string", "authority", "${applicationId}.provider"
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            debuggable true

            manifestPlaceholders = [ applicationIdWithSuffix: defaultApplicationId + ".debug" ]

            buildConfigField "String", "ACCOUNT_TYPE",  "\"${defaultApplicationId}.debug\""
            buildConfigField "String", "AUTHORITY", "\"${defaultApplicationId}.debug.provider\""

            resValue "string", "account_type", "${defaultApplicationId}.debug"
            resValue "string", "authority", "${defaultApplicationId}.debug.provider"
        }
    }
    lintOptions {
        abortOnError false
    }
}

AndroidManifest.xml

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

    <permission
        android:name="${applicationIdWithSuffix}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="${applicationIdWithSuffix}.permission.C2D_MESSAGE" />

    <application
        android:label="@string/app_name" >

        <provider
            android:name=".MyContentProvider"
            android:authorities="${applicationIdWithSuffix}.provider"
            android:exported="false"
            android:multiprocess="true" />
    </application>
</manifest>

xml

<sync-adapter
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="@string/authority"
    android:accountType="@string/account_type"/>

<account-authenticator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="@string/account_type"
    .../>

ContentProvider

, BuildConfig.

AUTHORITY = BuildConfig.AUTHORITY

, BuildConfig.

BuildConfig.ACCOUNT_TYPE

:

/-/strings.xml

<resources>
    <string name="app_name">MyApp debug EN</string>
</resources>

/-/strings.xml

<resources>
    <string name="app_name">MyApp debug FR</string>
</resources>

< > /-/strings.xml

<resources>
    <string name="app_name">MyApp EN</string>
</resources>

< > /-FR/strings.xml

<resources>
    <string name="app_name">MyApp FR</string>
</resources>
+7

Source: https://habr.com/ru/post/1612407/


All Articles