Android Studio missing external dependencies

前端 未结 3 713
星月不相逢
星月不相逢 2020-12-31 10:01

I have a library project. I want to use Android\'s new build system. Currently I\'m encountering a quite annoying scenario.

I have my dependencies defined on

相关标签:
3条回答
  • 2020-12-31 10:24

    Unfortunately, in the current version of Android Studio, the IDE is not completely integrated with the build system (gradle). You have to add the library once in gradle.build for compilation, and once via the GUI for code completion.

    Right click on your project, select "Open Module Settings". Acknowledge the warning. Select "Libraries", "+", and add the library you are using. You can search for libraries on Maven in the dialog that appears. You should select your libs dir for the jar. Finally, add the library to your code's module. If your app is MyApp, you probably have MyApp and MyAppProject. You need to add it to MyApp. (You can probably also directly add it from the "Modules" page.)

    To additionally get gradle to add the jar to your apk, make the following changes to your grade file. Replace:

    compile 'org.jsoup:jsoup:1.6.1'
    

    and similar with

    compile files('libs/jsoup-1.6.1.jar')
    

    Now it should all work.

    0 讨论(0)
  • 2020-12-31 10:31

    You can use 'Tools->Android->Sync project with Gradle files'. It will resolve the dependencies, download, and add them to external libraries.

    0 讨论(0)
  • 2020-12-31 10:31

    I commented following line from build.gradle file and it started working.

    //compile files('libs/android-support-v4.jar')
    

    enter image description here

    Previously dry build operation would succeed but when I would try to run on device there would be error

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define  Landroid/support/annotation/AnimRes;
    
    0 讨论(0)
提交回复
热议问题