Android practices: App system signature
This has plagued us for a long time.
We have always wanted to solve this problem by using non-source code compilation. Follow these steps.
The method for obtaining the system signature is as follows:
1. The android: sharedUserId = "android. uid. system" attribute must be used in the apk. Modify the Manifest file as follows:
<code class=" hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.linc.systemsigndemo" android:shareduserid="android.uid.system"> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"> <category android:name="android.intent.category.LAUNCHER"> </category></action></intent-filter> </activity> </application></manifest></code>
2. Compile the app without a signature (Android Studio)
Compile with command line
Windows: gradlew.bat assembleRelease Mac/linux: ./gradlew assembleRelease
3. Sign the apk system.
1) In the android source code build/target/product/security, find two key files: platform. x509.pem platform. pk8.
2), out/host/linux-x86/framework/signapk. jar find the system encapsulation tool signapk. jar
3) run the java-jar signapk. jar platform. x509.pem platform. pk8 test.apk testnew.apk command.
Problems encountered during installation:
Installation failed with message INSTALL_FAILED_SHARED_USER_INCOMPATIBLE.
It had been a problem for about half a month. At last, I thought it would be better to compile the source code.
1. Copy the Android Studio project to the source packages/apps/path.
2. Copy Android. mk from other projects such as Settings and make some modifications as follows:
LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_JAVA_LIBRARIES := bouncycastle conscrypt telephony-commonLOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 android-support-v13 jsr305LOCAL_MODULE_TAGS := optionalLOCAL_SRC_FILES := \ $(call all-java-files-under, app/src/main/java/) \LOCAL_PACKAGE_NAME := SystemSignDemoLOCAL_CERTIFICATE := platformLOCAL_PRIVILEGED_MODULE := trueLOCAL_PROGUARD_FLAG_FILES := proguard.flagsLOCAL_AAPT_FLAGS += -c zz_ZZinclude $(BUILD_PACKAGE)# Use the folloing include to make our test apk.include $(call all-makefiles-under,$(LOCAL_PATH))
3. Copy the res folder and Manifest file to the same directory as Android. mk (the root directory of the project)
4. Compile
mm -B
5. Two files, .odexand .apk, will be generated after success.
The former is an optimized executable program. In this case, you can install the apk file as a common application.
6. How to prove that the system signature has been obtained
You can use SystemClock. setCurrentTimeMillis to modify the system time to, as shown below:
mTvInfo.setText("time: "+SystemClock.currentThreadTimeMillis()); Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 12); c.set(Calendar.MINUTE, 15); long when = c.getTimeInMillis(); if (when / 1000 < Integer.MAX_VALUE) { Log.d(TAG,"set time"); mTvInfo.append("\nset time when: "+when); SystemClock.setCurrentTimeMillis(when); }
Good Luck!