Android Studio - PDFRendererBasic - Unable to replace sample.pdf?

℡╲_俬逩灬. 提交于 2019-12-05 09:57:38

Downgrade gradle version from 2.2.0 to 2.1.2 and crash will go away.

In the build.gradle(Project) replace

classpath 'com.android.tools.build:gradle:2.2.0'

with

classpath 'com.android.tools.build:gradle:2.1.2'

Same issue as you mentioned is reported and described here. Problem seems to be with the way Android Studio is creating the final apk file. While solution to manually repack the apk file is provided in the given link it is not very practical. The error seems not to have any other simple solution.

EDIT

Here is the solution from the provided link. The reported issue however mentions slightly different error message, so this may not work.

  1. Start Android Studio
  2. Click Import an Android code sample
  3. Select Graphics > Pdf Renderer Basic
  4. Click Next
  5. Click Finish.
  6. Click Run > Run 'Application'

Running the application implicitly creates the Application/build/outputs/apk/Application-debug.apk file.

6.a: Sanity check: Verify that the META-INF entries are at the end of the file:

$ unzip -lv Application/build/outputs/apk/Application-debug.apk
...
    1569  Defl:N      702  55%  12-16-14 17:35  c7cb7a03  META-INF/MANIFEST.MF
    1598  Defl:N      724  55%  12-16-14 17:35  034c0dfc  META-INF/CERT.SF
     776  Defl:N      605  22%  12-16-14 17:35  2be8b27c  META-INF/CERT.RSA
--------          -------  ---                            -------
 1565085           849785  46%                            21 files
  1. Re-sign the package, manually, with jarsigner. The intent of this is to ensure that the META-INF entries are at the beginning of the .apk:

    $ yes android | keytool -genkey -v -keystore demo.keystore -alias demo -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Mark Smith" $ cp Application/build/outputs/apk/Application-debug.apk A.apk $ zip -d A.apk META-INF/MANIFEST.MF $ zip -d A.apk META-INF/CERT.SF $ zip -d A.apk META-INF/CERT.RSA $ jarsigner -keystore demo.keystore -storepass android \ -keypass android -digestalg SHA1 -sigalg md5withRSA \ -signedjar A-unaligned.apk A.apk \ demo $ zipalign 4 A-unaligned.apk A-aligned.apk

  2. Install the re-signed package:

    $ adb uninstall com.example.android.pdfrendererbasic $ adb install A-aligned.apk

  3. Run the new package:

    $ adb shell am start com.example.android.pdfrendererbasic/.MainActivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!