Compiling android project with a library project fails with missing classes.jar

末鹿安然 提交于 2020-01-23 17:05:45

问题


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. 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 refers to api level 22 on my system.)

  3. I generated build files for the appCompat project:

    cd appCompat
    android update lib-project --target 1 --path .
    
  4. 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)
    

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.


回答1:


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.



来源:https://stackoverflow.com/questions/29766740/compiling-android-project-with-a-library-project-fails-with-missing-classes-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!