Overriding GCM permission package prefix with Gradle

前端 未结 3 846
耶瑟儿~
耶瑟儿~ 2021-02-05 01:58

I have a Gradle Android project that has 4 product flavors (each has it\'s own unique package name). The build.gradle file is prity much straightforward:

         


        
相关标签:
3条回答
  • 2021-02-05 02:32

    I've used:

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

    in the Android manifest - this appears to be resolved correctly.

    0 讨论(0)
  • 2021-02-05 02:43

    You can use some sort of inheritance AndroidManifest.

    The following rules are used when dealing with all the sourcesets used to build a single APK:
    
     - All source code (src/*/java) are used together as multiple folders generating a single output.
     - *Manifests are all merged together into a single manifest. This allows Product Flavors to have different components and/or permissions, similarly to Build Types.*
     - All resources (Android res and assets) are used using overlay priority where the Build Type overrides the Product Flavor, which overrides the main sourceSet.
     - Each Build Variant generates its own R class (or other generated source code) from the resources. Nothing is shared between variants.
    

    code:

      productFlavors {
            flav1 {
                packageName 'com.company.flav1'
                versionName calcVersion()
            }
    
            flav2 {
                packageName 'com.company.flav2'
                versionName calcVersion()
            }
    
            flav3 {
                packageName 'com.company.flav3'
                versionName calcVersion()
            }
    
            flav4 {
                packageName 'com.company.flav4'
                versionName calcVersion()
            }
        }
    
      sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aild.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }
    
            flav1 {
                manifest.srcFile 'flavor1/AndroidManifest.xml'
            }
    
            flav2 {
                manifest.srcFile 'flavor2/AndroidManifest.xml'
            }
    
            ...
        }
    

    Where flavor1 and flavor2 are folders in root project folder.

    In flavor1/AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.sample.someapp"
          android:versionCode="1"
          android:versionName="1.0">
    
    <permission android:name="com.company.flav1.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
    <uses-permission android:name="com.company.flav1.permission.C2D_MESSAGE" />  
    
    </manifest>
    

    In flavor2/AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.sample.someapp"
          android:versionCode="1"
          android:versionName="1.0">
    
    <permission android:name="com.company.flav2.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
    <uses-permission android:name="com.company.flav2.permission.C2D_MESSAGE" />  
    
    </manifest>
    

    And in root AndroidManifest everything else.

    0 讨论(0)
  • 2021-02-05 02:49

    The AndroidManifest.xml now merges correctly as of gradle 1.11, using the default settings.

    0 讨论(0)
提交回复
热议问题