You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在Android环境中运行PenAndPdf开源项目?

Hey there! I’ve messed around with PenAndPdf a bit before, so let me walk you through the steps to get it up and running in Android Studio without pulling your hair out.

1. First, Get Your Environment Ready

PenAndPdf relies on MuPDF and native C code, so you’ll need to make sure these tools are set up correctly:

  • NDK Version: The project is built around a specific NDK version (usually something like r21e or r23b—check the project’s build.gradle or README for the exact one). Download it via Android Studio’s SDK Manager (SDK Tools -> Show Package Details -> NDK (Side by side)).
  • CMake: You’ll need CMake to compile the native code. Grab it from the SDK Manager under SDK Tools.
  • Android Studio Stable Build: Avoid canary versions—stick to a stable release like Arctic Fox, Bumblebee, or newer to minimize compatibility headaches.
2. Fix Project Config After Import

Once you’ve pulled the code from GitHub and imported it into Android Studio, fix these common configuration issues first:

  • Update local.properties: Make sure this file has the correct paths to your SDK and NDK. If it’s missing, create it in the project root and add lines like:
    sdk.dir=/path/to/your/android/sdk
    ndk.dir=/path/to/your/android/ndk/your-ndk-version
    
  • Check Gradle Versions: Open the project-level build.gradle and ensure the Android Gradle Plugin version matches your installed Gradle version. For example, if you’re using Gradle 7.4, the plugin should be com.android.tools.build:gradle:7.4.0. Update one to match the other if there’s a mismatch.
  • Verify MuPDF Module: PenAndPdf depends on the MuPDF submodule. Check that settings.gradle includes include ':mupdf'—if not, add it and sync the project. If the MuPDF code is missing (submodules sometimes don’t clone automatically), run git submodule update --init --recursive in your project’s root directory via terminal.
3. Squash Common Compilation & Run Errors

Here’s how to fix the most annoying issues you’ll likely hit:

  • Native Code Compilation Failures: If you get errors about missing headers or undefined symbols, check the CMakeLists.txt files in both the main app and MuPDF modules. Ensure paths to MuPDF’s include directories are correct. Also, in the app-level build.gradle, under defaultConfig.externalNativeBuild.cmake, set abiFilters to architectures MuPDF supports:
    abiFilters 'armeabi-v7a', 'arm64-v8a'
    
  • Gradle Sync Issues: If sync fails repeatedly, try clearing Android Studio’s cache (File -> Invalidate Caches... -> Invalidate and Restart). You can also delete the .gradle and .idea folders in your project root, then re-sync.
  • Runtime Missing .so Files: If the app crashes on launch complaining about missing native libraries, make sure the MuPDF module is compiling correctly and generating .so files in the jniLibs directory. Check that the app module is set to include these libraries in its build.
  • Permission Errors: PenAndPdf needs storage access to open PDFs. Ensure the AndroidManifest.xml includes:
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
    
    For Android 10+, you’ll need to handle scoped storage or request the MANAGE_EXTERNAL_STORAGE permission if needed.
4. Finally, Run the App
  • Use a Real Device (If Possible): Emulators can be finicky with native code, especially for arm architectures. If you must use an emulator, choose an x86_64 image with Android 10 or higher, and enable ARM translation (some emulators have this built-in now).
  • Hit Run: If everything is set up right, select your device/emulator and click the run button. If it still fails, check the Logcat for specific error messages—they’ll tell you exactly what’s broken (e.g., missing dependencies, permission denials).

Pro tip: If you’re stuck on a specific error, copy the full log from the Build window or Logcat and search for it—chances are someone else has run into the same problem and posted a fix!

内容的提问来源于stack exchange,提问作者Korab Muhadri

火山引擎 最新活动