How to access dependencies of dependencies with gradle in android studio? - java

Am I missing something here? I'm using android studio. I will be developing two apps with a shared code base, so I made three modules in my android studio project. One module is a library project with shared code, and the other two are apps. This is an app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "omitted"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':lib')
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
this is the shared module's build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
My expectation is that my app should have access to the dependencies of the shared code module (for example 'com.android.support:appcompat-v7:26.1.0'). Is this wrong? I cannot find any way to pass on these dependencies to the dependent app.

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.

Related

ERROR: Failed to resolve: core Affected Modules: app

i updated android studio to version 3.5 and started new project and there is a mistake in gradle files i couldn't understand it what should i do ? i don't understand how gradle files work,
so would someone commanded to me a course or website teeth how is it work ?
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.hibaadil.myapplication897"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

Failed to resolve: com.google.android.material.material:1.0

I've been trying to get the floatingActionButton to work but it seems it's not working due to my gradle dependencies, the gradle code is shown below please i need some help on this,
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "-------------"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.android.material.material:1.0.0-alpha1;'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
There's a typo in your dependency definition. Remove semi-colon at end and replace . with : between com.google.android.material and material:1.0.0-alpha1
So all together, change
implementation 'com.google.android.material.material:1.0.0-alpha1;'
To
implementation 'com.google.android.material:material:1.0.0-alpha1'

:app:processDebugResources Error in Android Studio

Not quite sure why I keep getting this error:
errors
After some searching, it seems like the issue is in my build.gradle file but I cannot find it. I've attached the file, but also include the screenshot of my errors in case there is something I am missing.
but that did not changed anything.
Build.gradle file below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.0"
defaultConfig {
applicationId "com.cormac.splashscreen"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
refer this site
https://github.com/thevarungupta1/Android-Training-2/blob/master/SplashScreen/app/build.gradle
and
you seem forgot
implementation 'com.android.support:support-v4:28.0.0-alpha3'

this error in get inside latest version of android studio 3.1.2

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 26.1.0. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:customtabs:26.1.0
no any solution found please anyone help?
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "c.myapplication"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.airbnb.android:lottie:2.5.4'
}

Odd DexArchiveMergerException

I've encountered this issue in the past, and was able to fix it fairly easily. This time, however, I do not see what's causing it. The only change to the build.gradle I have made since it worked was implementation project(':sharedfiles') - a shared common module for wear/mobile. I didn't add this, I added the module as a dependency and this line was automatically added, so I doubt it is an error. I have multipleDexEnabled true and cannot find any conflicting dependencies. Any help would be appreciated, this is my first time using a common module. Here are the two build.gradle files.
Mobile Module
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "bhprograms.supremis"
minSdkVersion 23
targetSdkVersion 26
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
wearApp project(':wear')
implementation 'com.google.android.gms:play-services-wearable:+'
implementation files('libs/gson.jar')
implementation project(':sharedfiles')
}
The Common Module
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 23
targetSdkVersion 26
versionCode 1
multiDexEnabled true
minSdkVersion 23
targetSdkVersion 26
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('libs/gson.jar')
}
And, of course, the error.
Error:Execution failed for task ':mobile:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Solved by getting rid of implementation files('libs/gson.jar') in the mobile module. Not sure why this fixed it, likely because I was not using this jar anymore in the mobile module. Left it there as I may need it in the future if an experimental feature does not work, but this is what was causing the issue.

Categories