AndroidStudio - Module Dependencies in Gradle
You should put your library modules inside the Application Project. In order to specify a module dependency, simply:
- Right click on Application->Open Module Settings
- Click on the '+' icon
- Select the root directory for your library module you'd like to add.
- Follow the prompts
Then, this module will show up in your project. Then, you need to add it to Application as a library dependency. Once again, in your Module Settings:
- Select your Application module
- Select the Dependencies tab on the right
- Click the '+' icon on the bottom
- Select Module Dependency
- Select your desired library module
How to access dependencies of dependencies with gradle in android studio?
The answer is to use api
instead of implementation
in my shared module's 'build.gradle
dependencies.
ie. I want api 'com.android.support:appcompat-v7:26.1.0'
instead of implementation 'com.android.support:appcompat-v7:26.1.0'
Courtesey of Jaydip Kalani's comment and How do I share dependencies between Android modules
However as far as I'm aware there is no such thing as testApi
to replace testImplementation
.
Android Gradle include module dependencies in another module
In your Root Project -> build.gradle you should have something like:
allprojects {
repositories {
jcenter()
}
}
Add dependencies there!!
UPDATE
If you do not want all your modules to have the common dependencies but only specific modules then do this:
- Create a folder in your Root Project/gradleScript
Create a .gradle file in this folder (e.g. gradleScript/dependencies.gradle)
that looks like:ext {
//Version
supportLibrary = '22.2.1'
//Support Libraries dependencies
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
recyclerView : "com.android.support:recyclerview-v7:${supportLibrary}",
cardView : "com.android.support:cardview-v7:${supportLibrary}",
appCompat : "com.android.support:appcompat-v7:${supportLibrary}",
supportAnnotation: "com.android.support:support-annotations:${supportLibrary}",
]
}In your root project build.gradle add this line:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
// Load dependencies
apply from: 'gradleScript/dependencies.gradle'In your modules accordingly add this:
// Module build file
dependencies {
//......
compile supportDependencies.appCompat
compile supportDependencies.design
}
Hope this helps!!!
Android Studio gradle modules dependency error
i solved it, there are three types of android modules :
- Application module : contains
code
,resources
and the build produces.Apk
file - Android Library : contains
code
,resources
and the build produces.AAR
file - Java Library : contains
code
and the build produces.JAR
file
Application module can depend on the other two, i converted myshared
module to android library type that solved it.
Related Topics
Android Upload Video to Remote Server Using Http Multipart Form Data
Android Pagerview Between Activities
How to Pause Flash Content in an Android Webview When My Activity Isn't Visible
How to Schedule Notifications Using Workmanager
Edittext in Listview Loses Focus When Pressed on Android 4.X
Firebaseinitprovider: Firebaseapp Initialization Unsuccessful
Developing a Custom Lock Screen
How to Get Value of Some Field in Firebase Firestore Android
Android - Inner Element Must Either Be a Resource Reference or Empty
Google Sceneform - Is It Deprecated? Any Replacement
How to Combine Multiple Images into a Single Image in Android
Using Notifyitemremoved or Notifydatasetchanged with Recyclerview in Android
How to Display Menu Item with Icon and Text in Appcompatactivity
Android Scrollview Layout Problem
Sms Delivery Report in Android
Run-As Package 'A.B.C' Is Unknown - Galaxy S4 Jellybean or Android 4.3
Eclipse Android Project, How to Reference Library Within Workspace