先说下我电脑的软件环境配置:

adt-bundle-linux-x86_64-20131030

(adt-bundle-linux-x86_64-20131030/sdk/platforms下面的都是我从同时拷贝的,这个下载太繁琐了)

ndk是android-ndk-r9b

一、用ndk-build编译

1、进入例子的目录:

cd android-ndk-r9b/samples/hello-jni

2、跑以下命令生成build.xml

android list target //看一下

android update project -p . -s -t 3 //选择对应的target

3、$ANDROID_NDK/ndk-build

二、使用ant生成apk

ant debug

出现了如下问题:

djy@djy:~/AndroidTools/android-ndk-r9b/samples/hello-jni$ ant debug
Buildfile: /home/djy/AndroidTools/android-ndk-r9b/samples/hello-jni/build.xml


-set-mode-check:


-set-debug-files:


-check-env:
 [checkenv] Android SDK Tools Revision 22.3.0
 [checkenv] Installed at /home/djy/AndroidTools/adt-bundle-linux-x86_64-20131030/sdk


-setup:
     [echo] Project Name: HelloJni
  [gettype] Project Type: Application


-set-debug-mode:


-debug-obfuscation-check:


-pre-build:


-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.0
     [echo] Resolving Build Target for HelloJni...
[gettarget] Project Target:   Android 4.0
[gettarget] API level:        14
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /home/djy/AndroidTools/android-ndk-r9b/samples/hello-jni/bin/rsObj
    [mkdir] Created dir: /home/djy/AndroidTools/android-ndk-r9b/samples/hello-jni/bin/rsLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloJni...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------
[dependency] API<=15: Adding annotations.jar to the classpath.
     [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 1 source file to /home/djy/AndroidTools/android-ndk-r9b/samples/hello-jni/bin/classes


-post-compile:


-obfuscate:


-dex:
      [dex] input: /home/djy/AndroidTools/android-ndk-r9b/samples/hello-jni/bin/classes
      [dex] input: /home/djy/AndroidTools/adt-bundle-linux-x86_64-20131030/sdk/tools/support/annotations.jar
      [dex] Using Pre-Dexed annotations-07ccf53e4c762305df87014e8c03342d.jar <- /home/djy/AndroidTools/adt-bundle-linux-x86_64-20131030/sdk/tools/support/annotations.jar
      [dex] Converting compiled files and external libraries into /home/djy/AndroidTools/android-ndk-r9b/samples/hello-jni/bin/classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.nio.BufferOverflowException
       [dx] at java.nio.Buffer.nextPutIndex(Buffer.java:501)
       [dx] at java.nio.HeapByteBuffer.putShort(HeapByteBuffer.java:296)
       [dx] at com.android.dex.Dex$Section.writeShort(Dex.java:818)
       [dx] at com.android.dex.Dex$Section.writeTypeList(Dex.java:870)
       [dx] at com.android.dx.merge.DexMerger$3.write(DexMerger.java:437)
       [dx] at com.android.dx.merge.DexMerger$3.write(DexMerger.java:423)
       [dx] at com.android.dx.merge.DexMerger$IdMerger.mergeUnsorted(DexMerger.java:317)
       [dx] at com.android.dx.merge.DexMerger.mergeTypeLists(DexMerger.java:423)
       [dx] at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:163)
       [dx] at com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
       [dx] at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
       [dx] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
       [dx] at com.android.dx.command.dexer.Main.run(Main.java:230)
       [dx] at com.android.dx.command.dexer.Main.main(Main.java:199)
       [dx] at com.android.dx.command.Main.main(Main.java:103)


BUILD FAILED
/home/djy/AndroidTools/adt-bundle-linux-x86_64-20131030/sdk/tools/ant/build.xml:892: The following error occurred while executing this line:
/home/djy/AndroidTools/adt-bundle-linux-x86_64-20131030/sdk/tools/ant/build.xml:894: The following error occurred while executing this line:
/home/djy/AndroidTools/adt-bundle-linux-x86_64-20131030/sdk/tools/ant/build.xml:906: The following error occurred while executing this line:
/home/djy/AndroidTools/adt-bundle-linux-x86_64-20131030/sdk/tools/ant/build.xml:284: null returned: 2


Total time: 1 second

解决办法:

命令行输入android:

$android

在弹出的界面将Android SDK Build-tools从19改为18.1.1。

重行ant debug即可


Logo

更多推荐