使用库项目编译 android 项目失败,缺少 classes.jar [英] Compiling android project with a library project fails with missing classes.jar

查看:56
本文介绍了使用库项目编译 android 项目失败,缺少 classes.jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个依赖于 Android v7 appCompat 支持库的应用.当我尝试使用 Ant 构建项目时,我收到来自 dex 的错误消息,指出它无法从 appCompat 项目的 bin 目录中找到文件 classes.jar.这是我所做的:

I'm making an app that depends on the Android v7 appCompat support library. When I'm trying to build the project with Ant, I get an error from dex stating that it can't find the file classes.jar from the appCompat project's bin directory. Here's what I have done:

  1. 我将 SDK 下的 appCompat 目录复制到我的项目中.它现在是与 libs、res、src 等一起的顶级目录之一.
  2. 我将库添加到我的项目中:

  1. I copied the appCompat directory under the SDK over to my project. It is now one of the top-level directories along with libs, res, src etc.
  2. I added the library to my project:

android update project --target 1 --path . --library .\appCompat

(--target 1 指的是我系统上的 api 级别 22.)

(--target 1 refers to api level 22 on my system.)

我为 appCompat 项目生成了构建文件:

I generated build files for the appCompat project:

cd appCompat
android update lib-project --target 1 --path .

  • 我回到我的项目并尝试构建它:

  • I went back to my project and attempted building it:

    cd ..
    ant clean debug
    

    一切都很顺利,直到我得到以下信息:

    Everything goes smoothly until I get the following:

    -dex:
          [dex] input: C:\Users\Tuukka\Documents\app\bin\classes
          [dex] input: C:\Users\Tuukka\Documents\app\appcompat\bin\classes.jar
          [dex] input: C:\Users\Tuukka\Documents\app\appcompat\libs\android-support-v4.jar
          [dex] input: C:\Users\Tuukka\Documents\app\appcompat\libs\android-support-v7-appcompat.jar
          [dex] Pre-Dexing C:\Users\Tuukka\Documents\app\appcompat\libs\android-support-v4.jar -> android-support-v4-7d4b9d18b52617b1310b8c2397abe6b7.jar
          [dex] Pre-Dexing C:\Users\Tuukka\Documents\app\appcompat\libs\android-support-v7-appcompat.jar -> android-support-v7-appcompat-af2360631cde3dc57c1fde6f23204ddb.jar
          [dex] Converting compiled files and external libraries into C:\Users\Tuukka\Documents\app\bin\classes.dex...
           [dx]
           [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
           [dx] java.io.FileNotFoundException: C:\Users\Tuukka\Documents\app\appcompat\bin\classes.jar (No such file or directory)
    

  • appCompat\bin 中确实没有classes.jar.事实上,在查看整个构建输出后,似乎从未构建过这种东西,但Ant似乎期望它存在.

    There is indeed no classes.jar in appCompat\bin. In fact, after looking through the entire build output, it seems such a thing was never built, yet Ant seems to expect that it exists.

    我在这里遗漏了什么吗?任何帮助将不胜感激.

    Is there something I'm missing here? Any help would be greatly appreciated.

    推荐答案

    我认为这个问题是由于项目没有设置为库项目造成的.如果您手动设置所有内容,您可以通过将 android.library=true 添加到 [your project]/appCompat/project.properties 文件来解决此问题.

    I think this problem is caused by the project not being set up as a library project. If you are setting up everything by hand you can fix this by adding android.library=true to the [your project]/appCompat/project.properties file.

    这篇关于使用库项目编译 android 项目失败,缺少 classes.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆