Iam new in developing android library.Recently there was a requirement to integrate some part of my app to other client app. For that, I have uploaded an aar format library through sonatype to maven repository.
But the problem arises when i integrate this library to other app.I have encountered some error like-:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/android/volley/Response$ErrorListener;
and many more like that.
The problem which I think so far is coming from the multiple dependencies defined in both app and library.
Is there anything which iam doing wrong in my library and how can we remove the duplicate library from the app.
I have tried many options like "multidex enable true and preDexLibraries = false" option but none of that attribute work.
Any help is appreciated.
My library app level gradle is-:
apply plugin: 'com.android.library'
apply from: 'maven-push.gradle'
android {
compileSdkVersion 26
useLibrary 'org.apache.http.legacy'
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
consumerProguardFiles 'proguard-rules.pro'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
useProguard true
//consumerProguardFiles 'proguard-rules.pro'
buildConfigField "String", "BASEURL", PROD_SERVICE_URL
buildConfigField "String", "MERCHANT_ID", MERCHANT_ID
buildConfigField "String", "ACCESS_CODE", ACCESS_CODE
}
debug {
buildConfigField "String", "BASEURL", STAGING_SERVICE_URL
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.jpardogo.googleprogressbar:library:1.2.0'
implementation 'com.karumi:dexter:4.2.0'
implementation 'com.squareup.okhttp:okhttp:2.4.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
implementation 'com.squareup.okhttp:okhttp:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.7.0'
implementation 'org.jsoup:jsoup:1.7.3'
implementation 'com.mcxiaoke.volley:library:1.0.17'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.jakewharton:disklrucache:2.0.2'
//implementation 'com.google.android.gms:play-services-base:15.0.1'
//compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:multidex:1.0.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
task deleteJar(type: Delete) {
delete 'libs/jars/logmanagementlib.jar'
}
task createJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('libs/jars/')
include('classes.jar')
rename('classes.jar', 'logmanagementlib.jar')
}
createJar.dependsOn(deleteJar, build)
Thanks
In your library AndroidManifest.xml remove everything from Application tag:
<application/>
when you import the library in application, all dependencies you import in the library will be imported in the application so remove the any library you imported in library before in application gradle file
if there is a problem with merging the AndroidManifest.xml you can see the error in the Merged Manifest tab in the bottom left corner
Related
I just created an empty android project while including the dependencies I need for the project I got an error only when I add com.google.firebase or com.google.android.gms it will generate error below.
/Users/macbookair/Desktop/ANDROID/APPTEST/app/src/main/AndroidManifest.xml:22:18-91
Error: Attribute application#appComponentFactory
value=(android.support.v4.app.CoreComponentFactory) from
[com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91 is also present at
[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86
value=(androidx.core.app.CoreComponentFactory). Suggestion: add
'tools:replace="android:appComponentFactory"' to element
at AndroidManifest.xml:5:5-21:19 to override.
Please can anyone help me out, I have be trying for very long time to fix this error.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.fexample.android.appz"
minSdkVersion 18
targetSdkVersion 28
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7: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 'org.apache.httpcomponents:httpcore:4.4.10'
implementation 'com.squareup.okhttp3:okhttp:3.13.1'
implementation 'com.facebook.android:facebook-login:4.41.0'
//If I uncomment the below line it will trigger error
//implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
//implementation 'com.google.android.gms:play-services-auth:17.0.0'
//implementation 'com.google.firebase:firebase-core:17.2.0'
//implementation 'com.google.firebase:firebase-messaging:20.0.0'
}
android {
useLibrary 'org.apache.http.legacy'
}
apply plugin: 'com.google.gms.google-services'
android { sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/public'] } } }
From the below screenshot this implementation 'com.android.support:appcompat-v7:28.0.0' also has an error but when I build apk it create successfully, I don't think is good.
Dependencies using groupId com.android.support and androidx.* can not
be combined but found
IdeMavenCoordinates{myGroupId='com.android.support',
myArtifactId='support-fragment', myVersion='28.0.0', myPacking='aar',
myClassifier='null'} and
IdeMavenCoordinates{myGroupId='androidx.swiperefreshlayout',
myArtifactId='swiperefreshlayout', myVersion='1.0.0', myPacking='aar',
myClassifier='null'}
I'll suggest you try one of the following:
1) Migrate the whole project to use the androidx libraries which you can do under Refactor > Migrate to AndroidX from the menu bar.
2) Downgrade the versions of com.google.firebase and com.google.android.gms from 17.x.x to a lower version
I'm trying to use the android support recyclerView widget, and though I've added all the dependencies to my build.gradle file (I think), the line "import android.support.v7.widget.RecyclerView;" in my activity isn't resolving. I'm new to Android Studio, so I might be missing something very basic.
So far I've tried adding the google repository in allprojects of the project build gradle, as well as that of my module build gradle. I've also shifted around my dependencies and tried changing version numbers. And I tried invalidating caches and restarting. I do seem to be able to import "import androidx.recyclerview.widget.RecyclerView;", but that isn't the same from what I've heard.
This is my build gradle file:
//noinspection GradleCompatible
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.chaos"
minSdkVersion 20
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
customDebugType {
debuggable true
}
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:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:28.0.0'
//implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
androidTestImplementation 'android.arch.persistence.room:testing:1.1.1'
// implementation 'com.android.support:support-v7'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation ('androidx.test.espresso:espresso-core:3.2.0-alpha02', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
And then this is the import I'm attempting in my main activity. It seems I can import android.support.v4 libraries, but v7 isn't even an auto-complete option. I'd appreciate the help!
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
I expect the import line to resolve, as it currently doesn't.
If you are using Android X, try this dependency instead
implementation 'androidx.recyclerview:recyclerview:1.0.0'
I am working on Android Application using the Fire base Database. All the data stored perfectly on the Fire base.
The Problem comes when I make some changes and close the Application by Forcing android Studio to be Shut Down.
Now When I open Android to built Project It Gives Error of Stream output Folder as Null.
I have searched on Stack Overflow and find an answer with my Error Resemblance but I didn't understand the Answer completely.
Answer Searched
Here is my App Gradle Code
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.usmanali.medicineinvent"
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'
}
}
}
The dependancies in App Gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.google.firebase:firebase-database:11.0.4'
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'
}
here is build. Gradle File
buildscript {
repositories {
google()
jcenter()
}
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.0'
}
}
This problem is just Resolved by Deleting the .Gradle File in the Project Folder.
After .gradle File Deletion;
Built and Clean the Project.
I'm getting this ERROR message.
Could not find method implementation() for arguments [project ':app']
on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Here's my project level's gradle file :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url "https://maven.google.com" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "https://maven.google.com" }
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
implementation project(':app')
}
Here's my app's gradle file :
apply plugin: 'com.android.application'
apply plugin: 'java-library'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.therationalbloke.myapplication"
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-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation project(':app')
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'
}
NOTE : I'm already aware of the following.
The "compile" has been replaced by "implementation" in Gradle 3.0 or
higher.
Yes, I'm using Android Studio's latest version and according to Rob, I should prefer the old one. But the thing is that I was haunted
by a lot of technical issues in that version (a lot of them included
stuff which is now outdated).
I've read almost every solution to this problem on Stack Overflow, Github. All of them are either asking to use implementation() instead
of compile (which I'm already using), or they're asking to check if
the Gradle version is 3.0+.
I've tried changing all the "implementation" to "compile" on suggestion of one user on Stackoverflow.
I've tried importing a lot of libraries as suggested by a lot of people in different communities.
Some info about my Android Studio
Android Studio - 3.1.3
Android Plugin Version - 3.1.3
Gradle Version - 4.4
Screenshot of the situation
I've never seen something like implementation project(':app') on a gradle file.
Here you have an example of a working gradle file, try deleting implementation project(':app') and resync.
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.amvt_notebook4.codigoqrtest"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
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:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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.google.android.gms:play-services:10.0.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation files('build/libs/mail.jar')
implementation files('build/libs/additionnal.jar')
implementation files('build/libs/activation.jar')
implementation files('build/libs/jtds-1.3.1.jar')
implementation 'com.android.support:multidex:1.0.3'
}
There is no error when I try to run it on connected devices or on emulator but, when I try to build its apk file, it's generating this error. Please help me out if you find any clue of mistake here. Thanks
The error is:
Error:Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException:
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex`
The build.gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.ihtesham.demoapp"
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'
multiDexEnabled true
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
androidTestImplementation 'com.android.support.test:runner:1.0.1' //1.0.1
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
//Adding libraries
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.firebaseui:firebase-ui-auth:3.1.3'
implementation 'com.firebase:geofire-android:2.1.2'
implementation 'com.github.d-max:spots-dialog:0.7#aar'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:design:26.1.0' // 26.1.0
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.google.firebase:firebase-database:11.8.0' //11.8.0
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services:11.8.0'
implementation 'com.google.android.gms:play-services-auth:11.8.0' //11.4.2
testImplementation 'junit:junit:4.12'//11.8.0
}
apply plugin: 'com.google.gms.google-services'
The project's build.gradle is:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{
url 'https://maven.google.com'
}
maven{
url 'https://dl.bintray.com/glomadrian/maven'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
remove
multiDexEnabled true
Or do it
multiDexEnabled false
from your project's build.gradle because the exception you are facing is telling something about not being able to compile the dex code.
after removing that line or doing it false try to CLEAN and then ->REBUILD and go for buildapk.
if you are going for releasing your apk then you have to do some more amends in your application's build.gradle like this
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
multiDexEnabled false
}
in your program-rules pro file you have to put these lines too its good practice well to me actually
-keep class * {
public private *;
}
if that does not work! keep the multidexEnabled true and add this in your project dependencies
implementation 'com.android.support:multidex:1.0.2'