Android studio automatically generates apk s with system privileges

Keywords: Android OpenSSL Linux Eclipse

1 In Linux environment, take Android source directory as the root directory

cd build/target/product/security/

2. Generating Temporary File platform.pem

openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform.pem

3. Generate platform.p12 file in directory, it should be a digital certificate in essence.

The script is as follows:
OpenSSL PKCs 12-export-in platform.x509.pem-out platform.p12-inkey platform.pem-password pass:[password for JKS alias]-name [alias for jks]

Explain the meaning of the parameter:
1. -export: This option specifies that a PKCS#12 file will be created.
2. -in filename: Specifies the file read by the private key and certificate, defaulting to standard input. Must be in PEM format.
3. -out filename: PKCs 12 file specified for output, default to standard output.

  1. - inkey filename: Specifies the location of the private key file. If not specified, the private key must be specified in - in filename.
  2. - name name: specifies the friendly name of the certificate and the private key. When the file is imported with software, the name will be displayed.

For example, my

openssl pkcs12 -export -in  platform.x509.pem -out platform.p12 -inkey  platform.pem -password pass:123456 -name hoyouly

5. Generating eclipse and AS both recognize platform.jks

The script is as follows
keytool -importkeystore -deststorepass [jks password] - destkeystore. /[jks file] - srckeystore. / platform. p12 - srcstoretype PKCS12 - srcstorepass [jks alias password]

Explain the meaning of the parameter:

  1. - destkeystore < target keystore >
  2. - deststorepass < target repository password >
  3. - srckeystore < source keystore >
  4. - srcstoretype < source storage type >
  5. - srcstorepass < source repository password >

For example, my script:

keytool -importkeystore -deststorepass 123456 -destkeystore ./hoyouly.jks -srckeystore ./platform.p12 -srcstoretype PKCS12 -srcstorepass 123456

6 Configure gradle (app)

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.hoyouly.demo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    signingConfigs {
        release {
            storeFile file("../SignAPK/hoyouly.jks")  //Path relative to this document
            storePassword '123456'  //Password
            keyAlias 'hoyouly' //alias
            keyPassword '123456'    //Alias password
        }

        debug {
            storeFile file("../SignAPK/hoyouly.jks")
            storePassword '123456'
            keyAlias 'hoyouly'
            keyPassword '123456'
        }
    }
}

Reference link

Posted by kotun on Thu, 16 May 2019 11:35:38 -0700