Android實戰技巧之五十:App的系統簽名

來源:互聯網
上載者:User

Android實戰技巧之五十:App的系統簽名

這件事困擾我們多時了。
我們一直想用非源碼編譯的方式解決此事,按如下步驟。

這種擷取系統簽名的方法如下:
1、apk中需要使用android:sharedUserId=”android.uid.system” 這個屬性。在Manifest檔案修改,如下:

<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、將app做無簽名編譯(Android Studio)
用命令列編譯

Windows: gradlew.bat assembleRelease Mac/linux: ./gradlew assembleRelease

3、對apk進行系統簽名。
1)、在android源碼下build/target/product/security找到兩個密鑰檔案platform.x509.pem platform.pk8
2)、out/host/linux-x86/framework/signapk.jar找到系統封裝工具signapk.jar
3)、使用命令java -jar signapk.jar platform.x509.pem platform.pk8 test.apk testnew.apk

安裝時遇到的問題:

Installation failed with message INSTALL_FAILED_SHARED_USER_INCOMPATIBLE.

困擾了大概半個月,最後覺得還是源碼編譯吧。
1、將Android Studio項目複製到源碼packages/apps/路徑下
2、從其他項目如Settings複製Android.mk,做一些修改如下:

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、將res檔案夾和Manifest檔案拷到與Android.mk同級目錄(項目的根目錄)
4、編譯

mm -B

5、成功後會產生兩個檔案: .odex和.apk檔案
前者是最佳化過的可執行程式。此時可以把apk檔案當成普通的應用安裝即可。

6、如何證明已經獲得系統簽名
很簡單,使用SystemClock.setCurrentTimeMillis修改系統時間,將其修改為12:15,如下:

 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!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.