简体   繁体   English

无法制作带有.jar编译的android项目

[英]Unable to make an android project with a .jar compile

Really looked all over the place, but I'm at pretty much a deadlock. 真的到处都是,但是我几乎陷入了僵局。 I'm currently unable to compile any Android Project that uses an external .jar. 我目前无法编译任何使用外部.jar的Android项目。 Even if this is just an empty project it always returns the same error: 即使这只是一个空项目,它始终会返回相同的错误:

Error:Execution failed for task ':app:preDexDebug'. 错误:任务':app:preDexDebug'的执行失败。

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\\Program Files\\Java\\jdk1.8.0_60\\bin\\java.exe'' finished with non-zero exit value 1. com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'D'\\ Program Files \\ Java \\ jdk1.8.0_60 \\ bin \\ java.exe命令以非零退出值1。

Am I completely missing something? 我完全错过了什么吗? Are native-java (Netbeans) jars incompatible for Android? 本机Java(Netbeans)jar是否与Android不兼容?

Currently the process is: 当前的过程是:
- copy the .jar to the libs folder -将.jar复制到libs文件夹
- resync gradle -重新同步gradle
- clean rebuild -干净的重建
- try to run -尝试跑步
- death -死亡

Edit: For those of you who should ever run into this wall. 编辑:对于那些应该碰到这堵墙的人。 If you have pure JAVA jars that contain pre 6.0 JDK code and compile it with a higher level JDK, Android wil not recognize it and give you that specific error. 如果您具有包含6.0之前的JDK代码的纯JAVA jar,并使用更高级别的JDK进行编译,则Android将无法识别它,并给您特定的错误。 Compiling my netbeans project with JDK 5.0 fixed my problem and my Android projects finally run now. 使用JDK 5.0编译我的netbeans项目解决了我的问题,我的Android项目现在终于可以运行了。

In Netbeans, right click the libraries folder in your project > properties > sources and under Source/Binary Format, select JDK 5 (or lower). 在Netbeans中,右键单击项目>属性>源中的库文件夹,然后在源/二进制格式下,选择JDK 5(或更低版本)。 Your Android project should compile now with your jar. 您的Android项目现在应该使用jar进行编译。

  • First of all you need to update the you sdk to the current version of Android api like Android M (Api level 23) and also download the latest version of gradle. 首先,您需要将您的SDK更新到最新版本的Android api,例如Android M(Api级别23),还需要下载最新版本的gradle。 (ie use everthing latest and utilize the hard work of android sdk developers because that's for helping the android developers and android users) (即使用最新的东西,并利用android sdk开发人员的辛勤工作,因为这是为了帮助android开发人员和android用户)
  • and also use that for your app target version 并将其用于您的应用目标版本
  • Then restart android with invalidate cache and restart option 然后使用无效缓存和重新启动选项重新启动android
  • And then you should add .jar file to libs folder then click option 然后您应该将.jar文件添加到libs文件夹中,然后单击选项
    add as library 添加为库

Do you have this line of code in your build.gradle file?: 您的build.gradle文件中是否包含以下代码行:

compile fileTree(dir: 'libs', include: ['*.jar'])

And where is your libs folder located? 您的libs文件夹在哪里? It should be in the root folder of the module, not the whole prject. 它应该在模块的根文件夹中,而不是整个项目。

.
├── app
│   ├── app.iml
│   ├── build.gradle
│   ├── libs  <----- check this
│   │   ├── greendao-1.3.7.jar
│   │   ├── httpcore-4.3-beta1.jar
│   │   ├── mimecraft-1.1.1.jar
│   │   └── volley.jar
│   ├── proguard-rules.pro
│   └── src
│       ├── androidTest
│       └── main
├── android
│   ├── app
│   │   └── annotations.xml
│   └── content
│       └── annotations.xml
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── build.gradle
├── gradle.properties
├── gradlew
├── gradlew.bat
├── project-name.iml
├── local.properties
├── settings.gradle
└── settings.gradle.orig

Also, in my experience, most of the time java finished with non-zero exit code error is related to resources or other non-java related stuff. 而且,以我的经验,大多数时候, java finished with non-zero exit code错误java finished with non-zero exit code这与资源或其他与java无关的东西有关。 You should check out Gradle console and look for red lines, they contain actual error messages that you can check and fix. 您应该检出Gradle console并查找红线,其中包含可以检查和修复的实际错误消息。

gradle控制台截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM