简体   繁体   中英

How is “libs” created and maintained in a gradle android project?

I currently am not using the "libs" folder for my third party dependencies (it seems they are added automatically to build/intermediates/pre-dexed/) but noticed that it may help static code analysis so I would like to add it to the project. Note: I'm using maven dependencies .

My question: Are people using custom scripts to generate this folder? I hardly think that this is generated once and then manually maintained when there is a newer version available.

Please enlighten me!

With Android Studio AND Gradle, there is no need to use libs folder (except for old .jar library).

In fact you can develop Android app whitout Android Studio as in your build.gradle there is already a apply plugin: 'com.android.application'

Gralde is using Maven or jCenter via gradle dependencies to import libraries. Gradle and Android Gradle plugin will automaticly download the libs as you sayed in a build/ folder. It is not static and can be clean with the Clean projet on Android Studio. Also, Android Studio will add a warning when a new library version is available automaticly in your build.gradle.

Dont miss the old libs folder used to import .jar library

I currently am not using the "libs" folder for my third party dependencies (it seems they are added automatically to build/intermediates/pre-dexed/) but noticed that it may help static code analysis so I would like to add it to the project. Note: I'm using maven dependencies.

Don't confuse the libs folder with build/intermediates/pre-dexed/ folder.
Currently the gradle plugin for Android manages the build process and create these "internal" and intermediates folders.

My question: Are people using custom scripts to generate this folder? I hardly think that this is generated once

You don't have to create this folder. The Gradle plugin for Android manage it for your. Also it will be deleted and recreated when your run a gradlew clean command.

and then manually maintained when there is a newer version available.

No. Your dependencies are defined in your build.gradle file.
When you define a new version, Gradle downloads the new dependency and updates the intermediate folders.

You can define your dependencies in many ways:

dependencies{
   //You can create a folder and put jar files inside. You can use your favorite name, usually it is libs.
   compile fileTree(dir: 'libs', include: ['*.jar'])

   //The support libraries dependencies are in a local maven managed by SDK 
   compile 'com.android.support:appcompat-v7:23.0.0'

  // A Maven dependency
  compile 'com.squareup.picasso:picasso:2.5.2'

  //A local library
  compile project(':mylibrary')

  //An aar file. It requires to define a repository.
  //repositories{
  //    flatDir{
  //            dirs 'libs'
  //     }
  //}
  compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM