Android Gradle adding external library and nested external libraries to a project

后端 未结 3 800
抹茶落季
抹茶落季 2021-02-02 16:18

How do i add an external library and nested external libraries to an android project?


My project structure (Not allowed to change)

  • A
3条回答
  •  深忆病人
    2021-02-02 16:53

    In your top level settings.gradle (App1/settings.gradle) file do something like this for each library

    include ':library1'   
    include ':library2'   
    include ':library3'   
    include ':library4'   
    
    project(':library1').projectDir = new File(rootProject.projectDir, '../libraries/library1')
    project(':library2').projectDir = new File(rootProject.projectDir, '../libraries/library2')
    project(':library3').projectDir = new File(rootProject.projectDir, '../libraries/library3')
    project(':library4').projectDir = new File(rootProject.projectDir, '../libraries/library4')
    

    Remove the other settings.gradle files, you don't need them

    then in each build script you only need to use

    compile project (':library1')
    compile project (':library2')
    etc....
    

    as stated above just use a single settings.gradle file in the root project (App1).

    Then from your App1 folder run gradlew clean :library1:build to validate that library1 is building correctly.

    As for the issue about App1 complaining about missing libraries 3 & 4, are you sure you have no code in the app directly referencing these libraries, either that or the libraries are not being found when compiling library1. Build each library individually to validate they all build ok.

提交回复
热议问题