```<application android:allowBackup="true" android:icon="${app_icon}" android:label="${app_name}" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application>
(4) Get multi-channel information in code
String channel = WalleChannelReader.getChannel(getApplicationContext());
(5) Get multi environment information in code
int envType = BuildConfig.ENV_TYPE;
The BuildConfig here is dynamically generated by gradle:
package com.soubu.walledemo; public final class BuildConfig { public static final boolean DEBUG = Boolean.parseBoolean("true"); public static final String APPLICATION_ID = "om.soubu.walledemo.develop"; public static final String BUILD_TYPE = "debug"; public static final String FLAVOR = "develop"; public static final int VERSION_CODE = 1; public static final String VERSION_NAME = "1.0"; // Fields from product flavor: develop public static final int ENV_TYPE = 1; }
ENV_ The type field actually comes from our build gradle:
productFlavors { //development environment develop { buildConfigField "int", "ENV_TYPE", "1" applicationId 'om.soubu.walledemo.develop' manifestPlaceholders = [ app_name: "open-WalleDemo", app_icon: "@drawable/icon_develop" ] } {
Here, we'd better define a constant class to distinguish the types of these environments:
public class EnvType { public static final int DEVELOP = 1;//development environment public static final int CHECK = 2;//testing environment public static final int PRODUCT = 3;//Formal environment }
2. Packaged multi environment
Here, we directly execute the assemble command to package all buildType*productFlavors
Alternatively, you can use the command line:
gradle assemble
Execution result: 6 packages completed in 26 seconds: 2 versions * 3 environments
Here we can see that the debug packages are all 1.4M and the release packages are all 0.7M. Obviously, our obfuscation and compression configuration has taken effect, although I have not written obfuscation rules here
We install packages of three environments on our mobile phones:
The names and icons of the three packages are different. Obviously, the placeholder we configured in the manifest file has taken effect.
Then we click in to see the differences between the three app s:
In this way, we can select different network environments in the code according to the envType of the environment field.
The interface code is as follows:
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tvEnv = (TextView) findViewById(R.id.tv_env); TextView tvChannel = (TextView) findViewById(R.id.tv_channel); TextView tvPackage = (TextView) findViewById(R.id.tv_package); String channel = WalleChannelReader.getChannel(this.getApplicationContext()); int envType = BuildConfig.ENV_TYPE; String packageName = getPackageName(); switch (envType) { case EnvType.DEVELOP: tvEnv.setText("envType=" + "development environment "); break; case EnvType.CHECK: tvEnv.setText("envType=" + "testing environment"); break; case EnvType.PRODUCT: tvEnv.setText("envType=" + "production environment "); break; } tvChannel.setText("channel=" + channel); tvPackage.setText("package=" + packageName); } }
3. Packaging multi-channel
Create a new channel file in the root directory of Project:
anzhi #An Zhi baidu #Baidu huawei #Huawei oppo #oppo wdj #Pea pod xiaomi #millet yyb #Application treasure
Execute the gradle command:
(1) Channel package in package file
gradle assembleProductRelease -PchannelFile=channel
(2) Packaging channel packages in a custom array
gradle assembleProductRelease -PchannelList=qihu,vivo,lenovo
For more use of Walle library, see Github-walle
Running result: 8 packages completed in 17 seconds: 1 default package + 7 channel packages
Finally, here is the source code: WalleDemo
common problem
1. Configuration for signature file not found?
Khan, because my jks file is not uploaded in my Demo, you can add your own jks file and then in gradle Configure the password of the signature file in properties
In gradle Properties add the configuration key value of the signature file
In build The configured key is referenced in gradle
2. For develop ment, check and product, how to set the default environment if you directly run the code?
Click to view build variants in the lower left corner of Android studio, and then select to set the default run environment.
BuildVariants= buildTypes* productFlavors
Welfare at the end of the article!!
At the same time, after years of collection, I have collected a complete set of learning materials and HD detailed advanced learning guide and notes of Android architecture for free. I hope to have some reference and help for friends who want to become architects.
**The following is a screenshot of some materials, full of sincerity: it is especially suitable for Android programmers with development experience.
summary
Finally, in order to help you deeply understand the principles of Android related knowledge points and interview related knowledge, here are 24 sets of real interview questions analysis of Tencent, byte beating, Ali and Baidu 2019-2021 collected and sorted by me. I sorted the technical points into videos and PDF s (actually spent a lot more energy than expected), including knowledge context + many details.
There are also advanced architecture technology advanced brain map and Android development interview special materials to help you learn and improve the advanced level. It also saves you time to search for materials on the Internet to learn. You can also share them with your friends to learn together.
There are a lot of materials for learning Android online, but if the knowledge learned is not systematic, only a superficial taste when encountering problems and no further research, it is difficult to achieve real technology improvement. I hope this systematic technical system has a direction reference for you.
17222346)]
There are a lot of materials for learning Android online, but if the knowledge learned is not systematic, only a superficial taste when encountering problems and no further research, it is difficult to achieve real technology improvement. I hope this systematic technical system has a direction reference for you.
In 2021, although the road is bumpy and everyone is saying that Android will decline, don't panic, make your own plans and learn your own habits. Competition is everywhere, as it is in every industry. Believe in yourself, there is nothing you can't do, only what you can't think of. I wish you all the best in 2021.