Android can print multiple APP packages in the same set of code and install and run on the same mobile phone
- Android can print multiple APP packages in the same set of code and = = install and run on the same phone = =, and = = APP name and desktop icon are also different==
- Give different package names to the same set of codes, and set the APP name and desktop icon to judge which one is displayed according to each APP
- Use
- complete
Android can print multiple APP packages in the same set of code and install and run them on the same mobile phone. At the same time, the APP name and desktop icon are different
Need to be able to run on the same phone: only if the modified package name is different, can the same set of code run on the same phone.
Give different package names to the same set of codes, and set the APP name and desktop icon to judge which one is displayed according to each APP
In build.gradle under app:
apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.xxx.papplicationId1" minSdkVersion 14 targetSdkVersion 27 versionCode 1 versionName '1.0.0' // --------------------------Pay attention here-------------------------- // Add a sentence after the version name, which means that the dimension of the flavor dimension is the version number, so that the dimensions are unified flavorDimensions "versionCode" // ----------------------------------------------------------------------- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } buildToolsVersion '27.0.3' // --------------------------Pay attention here-------------------------- productFlavors { // General app app1 { // Set applicationId (it is important here that two apk s with the same applicationId are installed in the same Android phone at the same time) applicationId "com.xxx.applicationId1" // Automatically generate @ string/app_name as the name of app1 // Note: This is add. You can't have this field in string.xml. It will have the same name!!! resValue "string", "app_name", "app111" // Define fields such as app ﹣ icon, which are used in the Android manifest.xml file manifestPlaceholders = [app_icon : "@mipmap/ic_launcher", app_roundicon: "@mipmap/ic_launcher", // Because each APP package name is different, the third-party key of each APP needs to be configured separately // Modify the map appkey in Android manifest.xml map_appkey : "xxxxxxxxxxxxxx"] } // app2 app2 { applicationId "com.xxx.applicationId2" resValue "string", "app_name", "app222" manifestPlaceholders = [app_icon : "@mipmap/ic_launcher2", app_roundicon: "@mipmap/ic_launcher2", map_appkey : "xxxxxxxxxxxxx"] } } // ----------------------------------------------------------------------- // Remove the error of lint detection lintOptions { checkReleaseBuilds false abortOnError false } sourceSets.main { jniLibs.srcDirs = ['libs'] } } dependencies { ...... } allprojects { repositories { flatDir { dirs 'libs' } } }
Use
In Android manifest.xml:
<application android:name=".xxxxx" android:allowBackup="true" android:icon="${app_icon}" android:label="@string/app_name" android:roundIcon="${app_roundicon}" android:supportsRtl="true" android:theme="@style/AppTheme" tools:replace="android:allowBackup"> <!--tools:replace="icon,label,theme">--> <!-- Map appkey, Use build.gradle Dynamic value in --> <meta-data android:name="com.amap.api.v2.apikey" android:value="${map_appkey}"/>