AndroidManifest


Add the following configuration to the AndroidManifest.xml file.

android:sharedUserId="android.uid.system"

Sign APK file


Signing an APK using the apksigner tool is as follows:

apksigner sign --ks keystore.jks --key key.pk8 --cert cert.x509.pem xxx.apk

The .pk8 and .pem file were provided via device factory. The .jks is your own key file.

But the above method is too cumbersome to operate. Therefore, the better method is generate a keystore to sign the app at building.

Generate JKS


Generate a keystore with the keytool tool that comes with java.

./keytool-importkeypair -k key.jks -p password -pk8 xxx.pk8 -cert xxx.pem -alias key0

Then you can add these code in your android project.

android {
    signingConfigs {
        debug {
            storeFile file("path/to/key.jks")
            storePassword 'password'
            keyAlias 'key0'
            keyPassword 'password'
        }
        release {
            storeFile file("path/to/key.jks")
            storePassword 'password'
            keyAlias 'key0'
            keyPassword 'password'
        }
    }
}

Now, you can build any app as before.