Android Studio: Multi-Package name packaging

Source: Internet
Author: User

From: http://m.blog.csdn.net/u011315960/article/details/73251196

Objective

Recently a little busy, blog has fallen, today hurriedly write something to fill up.

A few days ago business to find me, want a vest bag, what is vest bag? Simply said is trickery, the name is different but the same function, we all know the application of the market according to the package name to distinguish whether it is the same app, this time you have to change the name of the package, so the egg hurt trip began.

Body

This kind of thing online has a lot of information, the whole process is this:

First, configure our Gradle file:

// 此处设置不同包名的apk信息    productFlavors {        // app生产环境配置        app {            applicationId ‘com.lzp.multipackagedemo‘            manifestPlaceholders = [app_name: "app", app_icon: "@mipmap/ic_launcher"] } // 马甲包的配置信息 app1 { applicationId ‘com.lzp.multipackagedemo1‘ manifestPlaceholders = [app_name: "app1", app_icon: "@mipmap/ic_launcher"] } } // lint检查,防止打包因为一些警告而停止 lintOptions { checkReleaseBuilds false abortOnError false }

Simply explain:

ApplicationID can be considered our package name.
Manifestplaceholders defines two variables, app_name and App_icon, in order to set the names of different icons and apps. Because I am lazy, the icon and the name will change, we will go to their own experiment.

After the setup, we will use the information above to open the Androidmanifest.xml:

<?xml version= "1.0" encoding= "Utf-8"?><ManifestXmlns:android="Http://schemas.android.com/apk/res/android"Package="Com.lzp.multipackagedemo" ><Applicationandroid:allowbackup="True"android:icon="${app_icon}"Android:label="${app_name}"Android:supportsrtl="True"Android:theme="@style/apptheme" ><activity android:name=<intent-filter>  <action android:name= " Android.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter> </activity> </application> </MANIFEST>         

We set the icon and lable information in application, referring to the variables defined in Gradle, and some people would ask, is it possible to modify packagename in the same way? This really does not, after the changes, the system will prompt you, you can not use the variables you defined, I hope you set ApplicationID to set the package name, and you configure the Activity,service and other information, can not find the object class, This is the role of ApplicationID in Gradle.

OK, if the settings are successful, the command for your different package names will appear in the Gradle window:

For convenience, I modified the code in mainactivity to display the current package name directly:

public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView) findViewById(R.id.textView); textView.setText(getPackageName()); }}

Packaged installation!!!

The app has been installed successfully, and the name is the same as we set it, look at the same content:


The package name is really different.

Extended

You think it's over??? Impossible, in the end the package name is not changed, I see for myself how to do, open the Anti-compilation tool (everyone to download it, everywhere), see my:

Oops I wipe, the package name doesn't actually change, so we can speculate that ApplicationID actually modifies the package name in the class file, so we getpackagename () changes, and the system is getpackcgename () To get the package name, so that the purpose of the difference between the app, it must be said that this method is really too chicken thief, but I like.

By the way, only release version to distinguish the installation, I planted on this.

Summarize

OK, today is so simple, then prepare some long content, continue to work hard!

Add: Friends using third-party libraries please note that because you have modified the package name, all of your third parties (login, share, payment, etc.) can not be used properly, remember to reapply.

Android Studio: Multi-Package name packaging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.