Error while setting up Instant Apps - android

I'm trying to implement Android Instant Apps Support to my app and I've followed this tutorial:
http://androidkt.com/instant-app/
Everything was going perfect and I've successfully completed the tutorial.
But, I faced this error:
Error:FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':appapk:preDebugBuild'. > Android dependency 'com.android.support:support-v4' has different
version for the compile (25.2.0) and runtime (27.0.1) classpath. You
should manually set the same version via DependencyResolution
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
My project targets the latest version of Android (Android 8.1 API 27) and because of this, all versions should be 27 and above.
I think that this error is because of com.android.support:support-v4 is version 25.2.0 but when I searched my whole project, I was not able to find that com.android.support:support-v4 or any file that is 25.2.0.
Here are my gradle files if necessary:
build.gradle (Project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
maven { url 'https://jitpack.io' }
}
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (module: app-base):
apply plugin: 'com.android.feature'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
baseFeature = true
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
multiDexEnabled true
versionCode 3
versionName "2.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation 'com.android.support:support-v4:27.0.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//compile 'android-support-v7-appcompat:25.0.1'
implementation 'com.github.HITGIF:TextFieldBoxes:1.3.8'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.firebase:firebase-crash:11.8.0'
implementation 'com.google.firebase:firebase-ads:11.8.0'
implementation 'com.google.android.gms:play-services-ads:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.android.gms:play-services:11.8.0'
implementation 'com.android.support:design:24.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:cardview-v7:24.2.1'
implementation 'com.android.support:customtabs:27.0.2'
testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
build.gradle (module: appapk):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "tr.k12.evrim.evrimnews.app"
minSdkVersion 21
targetSdkVersion 27
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 project(':app-base')
implementation 'com.android.support:appcompat-v7:27.0.1'
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'
}
build.gradle (module: instantapp):
apply plugin: 'com.android.instantapp'
android {
buildToolsVersion "26.0.2"
}
dependencies {
implementation project(':app-base')
}

With reference to google issue Tracker we were able to reproduce the issue in app with the same setup as in your build.gradle files.
The app can be successfully compiled when changing the com.android.support:support-v4 dependency in base from implementation to api and updating com.android.support:appcompat-v7:27.0.1 to 27.0.2.
The difference between implementation and api is that
implementation does not expose the dependency to other modules that depend on it, including libraries that need to be sync’d to the higher version (in this case, 25.x.x to 27).
While api dependencies will be exposed to all consumers of the library.

Related

How to fix Error : Could not find recyclerview-v7.jar (com.android.support:recyclerview-v7:28.0.0)

I am new in Android. I want to use recyclerview in my project and when I implement com.android.support:recyclerview-v7:28.0.0 to dependencies and build the project I got this error:
Could not find recyclerview-v7.jar (com.android.support:recyclerview-v7:28.0.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/support/recyclerview-v7/28.0.0/recyclerview-v7-28.0.0.jar
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
My build.gradle(Module:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 28
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(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.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'
implementation 'com.android.support:recyclerview-v7:28.0.0'
}
and build.gradle(Myapplication):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
By the way in sdk management, android support repository is installed and my Android sdk tools is 26.1.1
any one can help me to solve this error?
You have to install Support Repository from SDK Tools as shown in the picture.Tick mark the checkboxes in Support Repository and install

Android Studio: Execution failed for task: unable to merge dex

I just add a module to my android project. Android Studio builds the project correctly, but when I attempt to launch the app, I getting this error.
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
My project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.apollographql.apollo:apollo-gradle-plugin:0.4.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My module gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.apollographql.android'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.yamblet.smartliving"
minSdkVersion 21
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 project(':openpayandroid')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.airbnb.android:lottie:2.0.0'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.apollographql.apollo:apollo-runtime:0.4.4'
implementation "com.apollographql.apollo:apollo-android-support:0.4.4"
implementation 'com.apollographql.apollo:apollo-http-cache:0.4.4'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'jp.wasabeef:glide-transformations:2.0.1'
implementation 'com.master.android:permissionhelper:1.1'
implementation 'com.iamhabib:easy-preference:1.0.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.github.jkwiecien:EasyImage:2.0.2'
//RETROFIT
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
//JSON PARSING
implementation 'com.google.code.gson:gson:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.master.android:permissionhelper:1.1'
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'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
repositories {
maven { url "https://jitpack.io" }
mavenCentral()
}
apply plugin: 'kotlin-android-extensions'
Module gradle that I added
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile files('libs/devicecollector-sdk-2.5.jar')
compile files('libs/google-http-client-1.17.0-rc.jar')
compile files('libs/google-http-client-android-1.17.0-rc.jar')
compile files('libs/google-http-client-jackson2-1.17.0-rc.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jackson-core-asl-1.9.11.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/junit-4.10.jar')
}
I clean and rebuild the project but, the error persists in the build process. Also I add multiDexEnabled true but didnt work. Thanks for your help.
I executed this gradle, and it works only problem I can see here is implementation project(':openpayandroid'), i didn't included it as its your private library, but on my understanding openpayandroid is also including some same dependencies which is causing the problem, so solution can be to exclude that group from it, eg implementation project(':openpayandroid')
{
exclude group 'the dex error causing lib group'
}
if above does'nt work try this
in your project build.gradle try use same version of all the groups e.g.
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')) {
details.useVersion "26.1.0" // your version
}
I think this might help but if this doesn't work try to check which file is responsible for this dex error and edit your question
One more thing you have include permission helper twice, remove (but it might not be the problem )
Make sure you have multiDexEnabled true ie. multidex enabled in your app gradle under android section
In build.gradle in default config use
multiDexEnabled true
and add dependency like compile 'com.android.support:multidex:1.0.3'
and extend your application file with MultidexApplication and rebuild your project. This will help you.
If you update the dependencies recently try this answer
Just clean the project & re-build the project
Build -> Clean project
Build -> Rebuild project

Android Studio: Gradle Build Error No repositories are defined

Andriod Studio 3.3.1
gradle 4.4
I added firebase storage through the Android > Tools > Firebase option. However when I sync the gradle the build fails. This is the error that I'm getting:
Cannot resolve external dependency com.google.gms:google-services:3.2.1
because no repositories are defined. Required by:project :app
Does anyone know how to correct this error?
build.gradle (Module: APP)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.test"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.firebase:firebase-storage:15.0.0'
implementation 'com.google.firebase:firebase-auth: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.android.support:design:27.1.1'
//implementation 'com.google.android.gms:play-services:11.0.4'
}
buildscript {
dependencies {
classpath 'com.google.gms:google-services:3.2.1'
}
}
apply plugin: 'com.google.gms.google-services'
In my case, I have to add below code to project level gradle:
allprojects {
repositories {
google()
jcenter()
}
}
The error indicates that repositories is missing in order to determine from where google-services will be downloaded.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:3.2.1'
}
}
jcenter is a reference to bintray jcenter. Gradle can find the google-services:3.2.1 there.
In my case I was able to get it working by adding another repository scope to the top level.
repositories {
mavenLocal()
mavenCentral()
}
I was inspired to do so by this example.

More than one file was found with OS independent path 'META-INF/deserialization.kotlin_module'

I have to build an Android application using Kotlin that evaluates Kotlin codes. In order to accomplish this I need to import as dependences org.jetbrains.kotlin:kotlin-compiler and org.jetbrains.kotlin:kotlin-script-util as below:
rks module gradle
buildscript {
ext.kotlin_version = '1.2.31'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-compiler:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
than app module gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "it.matteopellegrino.kotlinsample"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "0.0.1"
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 "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
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'
compile project(":rks")
}
When importing these dependences Gradle sync works, but run fails with this error
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'META-INF/deserialization.kotlin_module'
I cannot exclude it in packagingOptions, because it would broke the entire kotlin run.
According to this article it seems a naming conflict between libraries, but the solutions provided does not work for me.
How can I solve this?

Dex Error while building the project

I am getting the following error when I try to build my project. This error occurs when I was trying to add JavaMail api in my project.
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
This is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.persi.eatery"
minSdkVersion 21
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'
}
}
productFlavors {
}
packagingOptions {
exclude 'META-INF/mailcap.default'
exclude 'META-INF/mimetypes.default'
}
defaultConfig {
multiDexEnabled true
}
}
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'
implementation 'com.android.support:design:26.1.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.sun.mail:android-mail:1.6.1'
implementation 'com.sun.mail:android-activation:1.6.1'
implementation project(':library')
}
apply plugin: 'com.google.gms.google-services'
My library gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Project gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url "https://maven.java.net/content/groups/public/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
P.S I have already tried Clean project followed by rebuild project as suggested in other answers but its still not working.Thanks in advance
Unable to merge dex
You have a dependencies conflict. Try to see your dependencies via command ./gradlew app:dependencies (Details here ). And you will see the next situation:
As you can see android-mail depends on android-activation. I think you don't need to use the line implementation 'com.sun.mail:android-activation:1.6.1'
P.S. For debugging builds you can use the next flag "--stacktrace". Then you can see more information about your issue.

Categories

Resources