2

我对 .apk 文件做了一些更改,之后我想以编程方式从 android mobile 对其进行签名,这怎么可能?

4

1 回答 1

0

我通过使用下面的代码得到它:

private void signAPK() {

    try {
        String generatedApkPath = GENERATE_APK_TO_DIRECTORY + apkname + ".apk";

        String signedApkPath = GENERATE_APK_TO_DIRECTORY + apkname + "-signed.apk";
        Log.i("Sign APK", "Going to create signed apk in:" + signedApkPath);

        ZipSigner zipSigner = null;
        zipSigner = new ZipSigner();

        zipSigner.setKeymode("testkey");

        zipSigner.signZip(generatedApkPath, signedApkPath);

        // After signing apk , delete unsigned apk
        new File(generatedApkPath).delete();

        Toast.makeText(getApplicationContext(),
                "'" + apkname + "-signed.apk' is generated at " + GENERATE_APK_TO_DIRECTORY, Toast.LENGTH_LONG)
                .show();

    } catch (Throwable t) {
        Log.e("Signing apk", "Error while signing apk to external directory", t);
        t.printStackTrace();
    }
}
于 2013-07-10T13:12:30.950 回答