Android package signature

1. What is packing?

Packaging is to generate an installation package based on signatures and other identifiers.

 

2. What is a signature?

1. A special string saved in the android application file (apk)

2. Used to identify different application developers: developer A, developer B

3. Multiple applications developed by one application developer use the same signature
> Just like a person writing an article, the signature is equivalent to the author's signature.
> If both applications are developed by the same developer, the signature is the same.
> This developer can be an individual, a company or a group.

 

3. Why use a signature

Reason 1: The most straightforward answer: system requirements

The Android system requires that every Android application must be digitally signed before it can be installed into the system, that is to say, if an Android application has not been digitally signed, there is no way to install it into the system!

Reason 2:

Applications developed by different programmers may have the same package name, causing one application to overwrite another.

For example: For example, after WeChat goes online, we can check its package name in some simple ways. At this time, you have also developed an app, and the icon, name and package name of the app are the same as WeChat, then the user is not aware of it. If you download your app in the case of the package name, the previous WeChat will be overwritten. If you write a virus in your app at this time, it will have a great impact on the user, which is why a signature is required. Because each developer's signature is different and encrypted, even if the icon, name and package name of your app are the same as WeChat, the system will prompt the user during the installation process that there are two applications with the same package name but different signatures.

Fourth, the danger of missing signatures

If your signature is lost, the user will first uninstall the previous application before the installation is successful, and the ranking in the application market will also start from 0, which is undoubtedly a huge harm to an app.

 

5. If digital signature is implemented (the following explanation is mainly for AS)

 

 

If not before then create one

Specify a file name here: Note: In as, the signature file keystore type file becomes the jks format file

Alisa means alias

The Build Type here has two values ​​release: indicates the release version debug: beta version



Click finish and wait for a while and it will be automatically generated. By default, the apk generated under bin in the as project also has a signature, but don't use that, use the apk we set by ourselves

 

6. Possible exceptions

Error message:
Error:(16) Error: "baidutieba_client_inavailable" is not translated in "en" (English) [MissingTranslation]
Error:(63) Error: "baidutieba" is not translated in "en" (English) [MissingTranslation]
Error :(67) Error: "share_to_baidutieba" is not translated in "en" (English) [MissingTranslation]

Solution: If there is a problem with that file, add the following code to that file

<?xml version="1.0" encoding="utf-8" ?>  
<resources

xmlns:tools="http://schemas.android.com/tools"  
  tools:ignore="MissingTranslation">  
</resources> 

 

Seven, multi-channel packaging (youmeng multi-channel packaging)

What is Multi-Channel Packaging and Why Use Multi-Channel Packaging?

1. The channel package is to add channel information in the installation package, that is, channel, corresponding to different channels, such as: Xiaomi market, 360 market, application treasure market, etc.

2. The significance of multi-channel packaging is to facilitate statistics.

 

8. The realization of Youmeng multi-channel packaging

1. Add the following code to the manifest file

<meta-data
 android:name="UMENG_CHANNEL"
 android:value="${UMENG_CHANNEL_VALUE}" />

 

2. Add the following content to the android{} of the module's build.gradle

productFlavors{
          wandoujia{
             manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
          }
          xiaomi{
             manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
          }
      }

 

3. Optimization 1:

productFlavors{
  wandoujia{
      //manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
  }
  xiaomi{
      //manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
  }
 }
 productFlavors.all { flavor ->
  flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
 }

4. Optimization 2 (using this method, the version number can be seen in our generated apk)

productFlavors{
    wandoujia{
        //manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
    }
    xiaomi{
        //manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
    }
 }
 productFlavors.all { flavor ->
    flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
 }
 applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.apk')) {
            def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
            output.outputFile = new File(outputFile.parent, fileName)
        }
    }
 }

 

5. Access to channels

private String getChannel() {
   try {
       PackageManager pm = getPackageManager();
       ApplicationInfo appInfo = pm.getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
       return appInfo.metaData.getString("UMENG_CHANNEL");
   } catch (PackageManager.NameNotFoundException ignored) {
   }
   return "";
}

6. Sign after the above steps are executed, wait for a while, at this time you go to the project directory, you will see the automatically typed channel package

 

7. Advantages and disadvantages

Pros: Safe

Cons: slow

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324509745&siteId=291194637