2015-04-20 51 views
0

这是一个通用的问题,但我在stackoverflow中找不到任何类似的问题,讨论最新版本的Android SDK/NDK的解决方案。如何打包Android NDK的示例?

我的目的是将Android NDK打包成apk文件。

所以:

  1. 我安装的Android NDK到/ opt目录 - 称之为的/ opt /。
  2. 而cd/opt //样本/其中是任何示例。
  3. 然后输入 “/选择// NDK建造” 时,其正常的编译:
 
/opt/android-ndk/ndk-build 
[arm64-v8a] Gdbserver  : [aarch64-linux-android-4.9] libs/arm64-v8a/gdbserver 
[arm64-v8a] Gdbsetup  : libs/arm64-v8a/gdb.setup 
[x86_64] Gdbserver  : [x86_64-4.9] libs/x86_64/gdbserver 
[x86_64] Gdbsetup  : libs/x86_64/gdb.setup 
[mips64] Gdbserver  : [mips64el-linux-android-4.9] libs/mips64/gdbserver 
[mips64] Gdbsetup  : libs/mips64/gdb.setup 
[armeabi-v7a] Gdbserver  : [arm-linux-androideabi-4.8] libs/armeabi-v7a/gdbserver 
[armeabi-v7a] Gdbsetup  : libs/armeabi-v7a/gdb.setup 
[armeabi] Gdbserver  : [arm-linux-androideabi-4.8] libs/armeabi/gdbserver 
[armeabi] Gdbsetup  : libs/armeabi/gdb.setup 
[x86] Gdbserver  : [x86-4.8] libs/x86/gdbserver 
[x86] Gdbsetup  : libs/x86/gdb.setup 
[mips] Gdbserver  : [mipsel-linux-android-4.8] libs/mips/gdbserver 
[mips] Gdbsetup  : libs/mips/gdb.setup 
[arm64-v8a] Compile  : hello-jni libs/arm64-v8a/libhello-jni.so 
[x86_64] Compile  : hello-jni libs/x86_64/libhello-jni.so 
[mips64] Compile  : hello-jni libs/mips64/libhello-jni.so 
[armeabi-v7a] Compile thumb : hello-jni libs/armeabi-v7a/libhello-jni.so 
[armeabi] Compile thumb : hello-jni libs/armeabi/libhello-jni.so 
[x86] Compile  : hello-jni libs/x86/libhello-jni.so 
[mips] Compile  : hello-jni libs/mips/libhello-jni.so 
  • 封装成APK,我使用的 “蚂蚁”,所以首先生成build.xml:
  • /opt/android-sdk-linux/tools/android update project --path。 --target机器人-21

  • “蚂蚁调试”
  •  
    
        Buildfile: /opt/android-ndk/samples/hello-gl2/build.xml 
    
        -set-mode-check: 
    
        -set-debug-files: 
    
        -check-env: 
        [checkenv] Android SDK Tools Revision 24.1.2 
        [checkenv] Installed at /opt/android-sdk-linux 
    
        -setup: 
         [echo] Project Name: GL2JNIActivity 
         [gettype] Project Type: Application 
    
        -set-debug-mode: 
    
        -debug-obfuscation-check: 
    
        -pre-build: 
    
        -build-setup: 
        [getbuildtools] Using latest Build Tools: 22.0.1 
         [echo] Resolving Build Target for GL2JNIActivity... 
        [gettarget] Project Target: Android 5.0.1 
        [gettarget] API level:  21 
         [echo] ---------- 
         [echo] Creating output directories if needed... 
         [mkdir] Created dir: /opt/android-ndk/samples/hello-gl2/bin/rsObj 
         [mkdir] Created dir: /opt/android-ndk/samples/hello-gl2/bin/rsLibs 
         [echo] ---------- 
         [echo] Resolving Dependencies for GL2JNIActivity... 
        [dependency] Library dependencies: 
        [dependency] No Libraries 
        [dependency] 
        [dependency] ------------------ 
         [echo] ---------- 
         [echo] Building Libraries with 'debug'... 
         [subant] No sub-builds to iterate on 
    
        -code-gen: 
        [mergemanifest] No changes in the AndroidManifest files. 
         [echo] Handling aidl files... 
         [aidl] No AIDL files to compile. 
         [echo] ---------- 
         [echo] Handling RenderScript files... 
         [echo] ---------- 
         [echo] Handling Resources... 
         [aapt] No changed resources. R.java and Manifest.java untouched. 
         [echo] ---------- 
         [echo] Handling BuildConfig class... 
        [buildconfig] Generating BuildConfig class. 
    
        -pre-compile: 
    
        -compile: 
         [javac] Compiling 6 source files to /opt/android-ndk/samples/hello-gl2/bin/classes 
    
        -post-compile: 
    
        -obfuscate: 
    
        -dex: 
          [dex] input: /opt/android-ndk/samples/hello-gl2/bin/classes 
          [dex] Found modified input file 
          [dex] Converting compiled files and external libraries into /opt/android-ndk/samples/hello-gl2/bin/classes.dex... 
    
        -crunch: 
         [crunch] Crunching PNG Files in source dir: /opt/android-ndk/samples/hello-gl2/res 
         [crunch] To destination dir: /opt/android-ndk/samples/hello-gl2/bin/res 
         [crunch] Crunched 0 PNG files to update cache 
    
        -package-resources: 
         [aapt] Creating full resource package... 
    
        package: 
        [apkbuilder] Current build type is different than previous build: forced apkbuilder run. 
        [apkbuilder] Creating GL2JNIActivity-debug-unaligned.apk and signing it with a debug key... 
        [apkbuilder] Found duplicate file for APK: AndroidManifest.xml 
        [apkbuilder] Origin 1: /opt/android-ndk/samples/hello-gl2/bin/GL2JNIActivity.ap_ 
        [apkbuilder] Origin 2: /opt/android-ndk/samples/hello-gl2/AndroidManifest.xml 
    
        BUILD FAILED 
        /opt/android-sdk-linux/tools/ant/build.xml:963: The following error occurred while executing this line: 
        /opt/android-sdk-linux/tools/ant/build.xml:974: The following error occurred while executing this line: 
        /opt/android-sdk-linux/tools/ant/build.xml:313: com.android.sdklib.build.DuplicateFileException: Duplicate files at the same path inside the APK 
         at com.android.sdklib.build.ApkBuilder.doAddFile(ApkBuilder.java:821) 
         at com.android.sdklib.build.ApkBuilder.addFile(ApkBuilder.java:507) 
         at com.android.sdklib.build.ApkBuilder.processFileForResource(ApkBuilder.java:872) 
         at com.android.sdklib.build.ApkBuilder.addSourceFolder(ApkBuilder.java:623) 
         at com.android.sdklib.build.ApkBuilder.addSourceFolder(ApkBuilder.java:605) 
         at com.android.ant.ApkBuilderTask.execute(ApkBuilderTask.java:356) 
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
         at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
         at java.lang.reflect.Method.invoke(Method.java:606) 
         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
         at org.apache.tools.ant.Task.perform(Task.java:348) 
         at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
         at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
         at java.lang.reflect.Method.invoke(Method.java:606) 
         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
         at org.apache.tools.ant.Task.perform(Task.java:348) 
         at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396) 
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
         at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
         at java.lang.reflect.Method.invoke(Method.java:606) 
         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
         at org.apache.tools.ant.Task.perform(Task.java:348) 
         at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
         at com.android.ant.IfElseTask.execute(IfElseTask.java:124) 
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
         at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
         at java.lang.reflect.Method.invoke(Method.java:606) 
         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
         at org.apache.tools.ant.Task.perform(Task.java:348) 
         at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
         at com.android.ant.IfElseTask.execute(IfElseTask.java:124) 
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
         at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
         at java.lang.reflect.Method.invoke(Method.java:606) 
         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
         at org.apache.tools.ant.Task.perform(Task.java:348) 
         at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
         at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
         at java.lang.reflect.Method.invoke(Method.java:606) 
         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
         at org.apache.tools.ant.Task.perform(Task.java:348) 
         at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396) 
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
         at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
         at java.lang.reflect.Method.invoke(Method.java:606) 
         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
         at org.apache.tools.ant.Task.perform(Task.java:348) 
         at org.apache.tools.ant.Target.execute(Target.java:435) 
         at org.apache.tools.ant.Target.performTasks(Target.java:456) 
         at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) 
         at org.apache.tools.ant.Project.executeTarget(Project.java:1364) 
         at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 
         at org.apache.tools.ant.Project.executeTargets(Project.java:1248) 
         at org.apache.tools.ant.Main.runBuild(Main.java:851) 
         at org.apache.tools.ant.Main.startAnt(Main.java:235) 
         at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) 
         at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) 
    
        Total time: 2 seconds 
    
    

    如何克服上述编译错误?

    谢谢。

    回答

    0

    首先,它看起来像你建立了hello-jni的本机端,然后构建和打包hello-gl2。这是两个不同的样本。你能否确保你留在同一个样本文件夹中?

    我还强烈建议您将/opt/android-ndk-r10e,/opt/android-sdk-linux/tools/opt/android-sdk-linux/platform-tools添加到PATH环境变量中。只需将此行添加到您的~/.profile,然后重新启动您的终端。

    export PATH=${PATH}:/opt/android-ndk-r10e;/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools" 
    

    这样,你应该能够访问任何Android工具,如ndk-buildadbandroid,而无需指定其绝对路径。

    如果这没有帮助,请尝试使用ant clean && ant debug清理并重建您的示例。如果还是不行,请尝试删除如下:

    • 斌/
    • 根/
    • 库/
    • OBJ/
    • 的build.xml
    • local.properties
    • ProGuard的项目。XML

    ,然后再试一次:

    ndk-build NDK_DEBUG=1 
    android update project --path . --target android-21 
    ant debug 
    

    一切都应该工作。如果它仍然不起作用,我会建议启动android(不带参数)来启动Android SDK Manager。确保你是最新的,并确保你已经安装了API平台的API平台21,如果这是你想使用的API级别。截至今日的最新Android SDK工具应为修订版24.2。确保你有最新的android-ndk。今天最新的应该是r10e。

    祝你好运!