将 jar 导入 Android Studio 项目
Importing jar into Android Studio project
目前我遇到这个错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access0(Main.java:83)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing db/DbFacade.class
1 error; aborting
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
E:\Program Files (x86)\Android\sdk\build-tools\build-tools-21.1.2\dx.bat --dex --output E:\Documents\Workspaces\AndroidStudio\Peanuts\app\build\intermediates\pre-dexed\debug\Peanuts-d65a672244db794ef4112fb86dd03a66b2b8790f.jar E:\Documents\Workspaces\AndroidStudio\Peanuts\app\libs\Peanuts.jar
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access0(Main.java:83)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing db/DbFacade.class
1 error; aborting
我在 app/libs 创建了一个目录 "libs"。与我的 "build" 和 "src" 目录相同级别。
然后我将我的 jar ("Peanuts.jar") 复制到那个文件夹中。
接下来,我右键单击它并选择 'Add as library'。
这个 .jar 使用了另外 2 个 jar,一个用于 json,另一个用于 mysql。我在 eclipse 中创建了 JAR,EXPORT > JAVA > RUNNALE JAR 并选中了“将所需的库提取到生成的 jar 中。
我的 app.iml 包含:
<orderEntry type="library" exported="" name="Peanuts" level="project" />
我的 build.gradle 包含:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.+'
compile files('libs/Peanuts.jar')
}
这是因为 Peanuts 和 appcompat 有一些共同的文件。尝试删除 appcompat 并清理并重建应用程序。它可能工作正常。
目前我遇到这个错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access0(Main.java:83)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing db/DbFacade.class
1 error; aborting
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
E:\Program Files (x86)\Android\sdk\build-tools\build-tools-21.1.2\dx.bat --dex --output E:\Documents\Workspaces\AndroidStudio\Peanuts\app\build\intermediates\pre-dexed\debug\Peanuts-d65a672244db794ef4112fb86dd03a66b2b8790f.jar E:\Documents\Workspaces\AndroidStudio\Peanuts\app\libs\Peanuts.jar
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access0(Main.java:83)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing db/DbFacade.class
1 error; aborting
我在 app/libs 创建了一个目录 "libs"。与我的 "build" 和 "src" 目录相同级别。
然后我将我的 jar ("Peanuts.jar") 复制到那个文件夹中。
接下来,我右键单击它并选择 'Add as library'。
这个 .jar 使用了另外 2 个 jar,一个用于 json,另一个用于 mysql。我在 eclipse 中创建了 JAR,EXPORT > JAVA > RUNNALE JAR 并选中了“将所需的库提取到生成的 jar 中。
我的 app.iml 包含:
<orderEntry type="library" exported="" name="Peanuts" level="project" />
我的 build.gradle 包含:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.+'
compile files('libs/Peanuts.jar')
}
这是因为 Peanuts 和 appcompat 有一些共同的文件。尝试删除 appcompat 并清理并重建应用程序。它可能工作正常。