Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different module file by flavor

I'm trying to implement play services and huawei services in the same app, but want to be able to configure which one to use by flavor. Each flavor uses it's own applicationIdSuffix. So for each different flavor, huawei plugin fails and I cannot compile.

I have app module that contains agconnect-services.json file in it's root. How could I specify different versions of this file for each build flavor?

If it's not possible, then in my root build.gradle file I have this line:

classpath 'com.huawei.agconnect:agcp:1.1.1.300'

Is it possible to use this line only on specific flavor?

like image 637
SMGhost Avatar asked May 11 '20 09:05

SMGhost


People also ask

What are build variants?

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

What is missingDimensionStrategy?

void missingDimensionStrategy ( String dimension, String requestedValue) Specifies a flavor that the plugin should try to use from a given dimension in a dependency. Android plugin 3.0. 0 and higher try to match each variant of your module with the same one from its dependencies.

What is buildtype in Gradle?

Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle.

How to change build variant?

NOTE: By default, the Android Studio will generate "debug" and "release" Build Types for your project. So, to change a Build Type, all you need to do is just select your Build Type from the Build Variant and after the project sync, you are good to go.

How to use product flavors in this library?

This library is an enterprise entity and different clients have different requirements with respect to minSdkVersion, targetSdkVersion, support library versions and other internal dependencies. Using product flavors on a regular applications is easy. Just add the productFlavors block and you are good to go.

How do I add flavor specific files to the source directory?

If you want to have flavor specific files, you will have to omit the file from main, and add it to each flavors source directory directly.

How to create different types of flavors in Android Studio?

As you can see, just by defining the flavorDimensions and dimension attribute, the product flavors can be grouped, and Android creates variants that are all possible combinations of flavors of all types of dimensions and build types. These variants are reflected everywhere, including the build variants tab on lower left side of android studio.

How do I build multiple flavors in Visual Studio Code?

To build and run (or debug) any of the multiple flavors, Click the Build Variants tab, or select Build – Select Build Variant, and select the desired variant. While building multiple flavors, you might come across a situation where each flavor will require its own specific code file.


2 Answers

The possible cause is that your AppGallery Connect plug-in version is not the latest one. Please upgrade it by referring to HUAWEI AppGallery Connect Guide. To support multiple channels, you need to add the agconnect-services.json file to the folder of only the Huawei channel and ensure that the AppGallery Connect plug-in version in the project is 1.2.1.301 or later (classpath'com.huawei.agconnect:agcp:1.2.1.301'). If the plug-in version is earlier than 1.2.1.301, upgrade it to 1.2.1.301 or later. To obtain the latest AppGallery Connect plug-in version, please refer to Configuring Address Information for the AppGallery Connect SDK.

The configuration procedure is as follows: If your app needs to support multiple build types or flavors, configure the agconnect-services.json configuration file downloaded from AppGallery Connect for your app to implement the function. The agconnect-services.json file provides configuration information required by various services in your AppGalleryConnect project. Therefore, if you need to use multiple flavors to release different app versions, copy the agconnect-services.json file to the folder of each flavor and configure it. To support multiple build types, such as release, debug, rest, and mirror for your app, set buildTypes in the build.gradle file in the app directory. You also need to copy the agconnect-services.json file to the folder of each build type. If your project needs to support different app packages for different channels, the package name needs to vary depending on the channel. Change the package name in productFlavor in the build.gradle file under the app directory.

like image 52
shirley Avatar answered Oct 19 '22 22:10

shirley


The possible cause is that your AppGallery Connect plug-in version is not the latest one. Please upgrade it by referring to HUAWEI AppGallery Connect Guide. To support multiple channels, you need to add the agconnect-services.json file to the folder of only the Huawei channel and ensure that the AppGallery Connect plug-in version in the project is 1.2.1.301 or later (classpath'com.huawei.agconnect:agcp:1.2.1.301'). If the plug-in version is earlier than 1.2.1.301, upgrade it to 1.2.1.301 or later. To obtain the latest AppGallery Connect plug-in version, please refer to Configuring Address Information for the AppGallery Connect SDK.

The configuration procedure is as follows: If your app needs to support multiple build types or flavors, configure the agconnect-services.json configuration file downloaded from AppGallery Connect for your app to implement the function. The agconnect-services.json file provides configuration information required by various services in your AppGalleryConnect project. Therefore, if you need to use multiple flavors to release different app versions, copy the agconnect-services.json file to the folder of each flavor and configure it. To support multiple build types, such as release, debug, rest, and mirror for your app, set buildTypes in the build.gradle file in the app directory. You also need to copy the agconnect-services.json file to the folder of each build type. If your project needs to support different app packages for different channels, the package name needs to vary depending on the channel. Change the package name in productFlavor in the build.gradle file under the app directory.

like image 31
zhangxaochen Avatar answered Oct 19 '22 22:10

zhangxaochen