Dependency configuration for projects under Android Studio
background
The project needs to use an open source repository on GitHub, which has been configured with dependencies (importing jar packages or Lib dependencies) in the eclipse environment, but has not been swipelistview under Android Studio. The internet looked up the relevant information and found the answer on the StackOverflow. According to the above introduction, the actual situation, the completion of the dependency configuration.
StackOverflow Answer Address
There are two ways to make a dependency configuration.
1. Using the AAR package (this is not very clear about the principle and the effect, simply check the correlation with MAVEN, compared with the jar package, you can use the resource file--jar package can not use its resource files). For example swipelistview
, the following lines of code set the address of the MAVEN remote library and the AAR package dependency.
repositories { mavenurl‘http://clinker.47deg.com/nexus/content/groups/public‘ }}dependencies { compile (‘com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT@aar‘) { transitivetrue }}
- Use local lib dependency (local copy of library file)
The first step is to recommend the following directory structure
-root -lib -abs build.gradle src res -myModule build.gradle settings.gradle
Import module sequence of operations:
File->import Module->select Source Location->ok->finish
Description:
The first-level directory root is the directory of the root project, which is the name of project.
The second-level directory MyModule is the name of the module, and Lib is a folder under root.
Level Three directory ABS is the LIB library file that will be dependent.
Project and Module,project for Android studio are equivalent to Eclipse's Wrokspace,module project, which is dependent on the module under the same project.
The second step, in the document settings.gradle
should be this
include‘:myModule‘‘:lib:abs‘
With "Enclosed is the module name under Project, you can see that the module ABS is a relative path."
In the third step, the following In lib/abs/build.gradle
may be true:
Buildscript{repositories {mavencentral ()}Dependencies{classpath ' com.android.tools.build:gradle:0.7.+ ' }}apply plugin:' Android-library 'Android{compilesdkversion buildtoolsversion "19.0. 0" Defaultconfig {minsdkversion XX targetsdkversion }Sourcesets{main {manifest.srcfile ' androidmanifest.xml ' java.srcdirs = [
' src '] resources.srcdirs = [
' src '] res.srcdirs = [
' res '
]}
}}}dependencies{compile ' com.android.support:support-v4:19.0.0 ' }
The original answer suggestedRemove the supportV4.jar from your local abs library.
Fourth step, then add the dependencies in the file myModule/build.gradle
dependencies
:
{ repositories { mavenCentral() } { classpath ‘com.android.tools.build:gradle:0.7.+‘ }‘android‘{ compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion XX targetSdkVersion 19 } } { // Libraries compile project(‘:lib:abs‘) }
Fifth step, finally in myModule/build.gradle
, add:
dependencies { ‘com.android.support:support-v4:19.0.0‘ // Libraries compile project(‘:lib:abs‘) }
However, depending on my actual operation, it is not necessary to transfer the dependencies in the Lib library to the main module, that is, the third and fifth steps are not performed, only the fourth step is performed. This should be decided according to the actual situation ~
The problem is that my two module's build tools version is inconsistent, causing the build to be unsuccessful, and my solution is to replace the lower one with the higher version to solve the problem.
Finally, the corresponding package name + class name can be imported directly in the project!
Dependency configuration for projects under Android Studio