4

I would like to create 2 different APKs (release and debug) using Gradle and I want to use different names for them ('appName' and 'appName debug').

I've found some solutions but it doesn't work for me:
link 1
link 2

I would like to install both apks on the device but I have the following error:

 Duplicate resources: 
 ...\src\release\res\values\config.xml:string/config_app_name,
 ...\src\main\res\values\config.xml:string/config_app_name

If I delete the config_app_name key from the main\res\values\config.xml then Gradle says the the key was not found.

I have 3 manifest files:

...\src\main\AndroidManifest.xml (this uses the `android:label="@string/config_app_name"`)

...\src\release\AndroidManifest.xml

...\src\debug\AndroidManifest.xml

buildTypes {

    debug {
        packageNameSuffix ".debug"
        versionNameSuffix "-debug"
        buildConfig "public static final String PROVIDER_AUTHORITY = \"" + PROVIDER_DEBUG + "\";"
        signingConfig signingConfigs.debug
    }
    release {
        buildConfig "public static final String PROVIDER_AUTHORITY = \"" + PROVIDER_RELEASE + "\";"
        signingConfig signingConfigs.release
    }
}

sourceSets {
    debug {
        java.srcDirs = [
                'src/main/java']
        res.srcDirs = [
                'src/main/res',
                'src/debug/res']
    }

    release {
        java.srcDirs = [
                'src/main/java']
        res.srcDirs = [
                'src/main/res',
                'src/release/res']
    }
}

Is it possible to use one common key (strings, integers, dimens) in the main part of the project and override it in the release/debug part?

Thanks in advance.

2 Answers 2

1

I just realized that it was only a naming issue. The name of the release package was misspelled. Sorry for this stupid problem.

Now the merge is working as expected.

Sign up to request clarification or add additional context in comments.

Comments

1

Look here: http://tools.android.com/tech-docs/new-build-system/resource-merging

You defined multiple resources sources for build type. In such case they have same priority and can cause conflicts.

If you want correct merging you need to create separate main source set. It will have less priority than build types resources.

sourceSets {

    main {
        java.srcDirs = ['src/main/java']
        res.srcDirs = ['src/debug/res']

    }

    debug {
        res.srcDirs = ['src/debug/res']
    }

    release {
        res.srcDirs = ['src/release/res']
    }
}

But with such directory structure it must work out from the box without sourceSets definition.

1 Comment

I have a big project and I need the sourceSets declaration because some of the build types are using more than 2 srcDirs. But thank you for your explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.