Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

android - Using a different manifestPlaceholder for nested Flavors

I do have a structure like below. I wanna use different manifestPlaceHolder like this, projectXTest, projectXDev, projectXProd all uses different manifestPlaceHolder while projectYTest,Prod,Dev uses same manifestPlaceHolder. What i can do beside putting that values to string.xml for all different flavors

android {
    buildTypes{
        debug{
            // Some debug setup
        }
        release{
            // Some release setup
        }
    }


   flavorDimensions "project" , "default"
    productFlavors {
        projectX{
         dimension 'project'
           }
       
        projectY{
          dimension 'project'
           }

        Test{
          dimension 'default'
           }
        Dev{
          dimension 'default'
           }
        Prod{
          dimension 'default'
           }
    }
}
question from:https://stackoverflow.com/questions/65662220/using-a-different-manifestplaceholder-for-nested-flavors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since I could find an out of this. I followed this steps. I hope, If somebody find her/himself in this situation, this helps.

Firstly

Put a manifest to desired flavors directory, for my example I've put android manifest to src/projectY and src/projectX

Beware these not to be full manifest. It should be layered like below

<manifest>
  <application>
    <activity>
        android:name=".x.loginActivity"
        tools:node="merge" // this is must
        // your flavor spesific code
    </activity>
  </application>
</manifest>

Secondly

Delete your code to minimum in main XML. What i mean that manifest you've created in src/flavor will be merged with main one. so that delete what you want to seperate and leave what you want to used common in main.

Thirdly

Give different manifestPlaceholder name if you need to seperate prod,dev and staging. For example,

src/projectX/manifest.xml

 <activity>
    .
    .
    android:host='${projectXHost}'
    .
    </activity>

src/projectY/manifest.xml

<activity>
.
.
android:host='${projectYHost}'
.
</activity>

in gradle

productFlavors{

 prod {
   manifestPlaceholders = [projectXHost : 'xxx' , projectYHost : 'yyy']
}

}

Since this is my first answer, I'm sorry with layout and expressions. I hope you can understand what I mean. Have a good day


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...