I'm using Android Studio. I have two modules: the app (UI) and a library. When tested separately, both compile and work as they should, but when I try to use some of the library classes on the app, I can't build the project. I get this error:
Error: Program type already present: org.apache.xmlbeans.xml.stream.Location
My library build.gradle has just a few lines:
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.apache.poi:poi:3.17'
implementation 'org.apache.poi:poi-ooxml:3.17'
}
sourceCompatibility = "7"
targetCompatibility = "7"
Then my app's build.gradle is this
android {
compileSdkVersion 28
defaultConfig {
applicationId "skrb.appprueba"
minSdkVersion 21
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'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.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.android.support:design:28.0.0'
implementation project(path: ':coreLib')
}
When adding this (implementation project(path: ':coreLib'), I get the error and I don't know how to solve it.
Things that I tried:
Cleaning and rebuilding the project.
Setting multiDexEnabled to true
according to the error message, it should rather be:
implementation (project(path: ":coreLib")) {
exclude group: "org.apache.xmlbeans"
}
Try this one:
implementation(project(path: ':coreLib')) {
exclude module: 'poi'
exclude module: 'poi-ooxml'
}
Here you could find more information why this error happen.
Related
I am using Android Studio 4.0.1. The following error occurs when I try to produce a debug version of the program. (No problem to produce a release version!)
Create Debug Version
ERROR
Entry name 'javax/annotation/CheckReturnValue.java' collided
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
//apply plugin: 'com.google.firebase.firebase-perf'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ai"
minSdkVersion 19
targetSdkVersion 28
versionCode 6
versionName "0.3.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix '.dev'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.kailashdabhi:om-recorder:1.1.5'
implementation 'com.fxn769:musicwave:1.0'
implementation 'com.tbuonomo.andrui:viewpagerdotsindicator:4.1.2'
// implementation "androidx.viewpager2:viewpager2:1.0.0"
//firebase
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
// implementation 'com.google.firebase:firebase-perf:19.0.5'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.GrenderG:Toasty:1.4.1'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
implementation 'com.github.amirdew:JSON:v1.0.0'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.github.ohoussein.playpauseview:playpauseview:1.0.2'
implementation 'com.nabinbhandari.android:permissions:3.7'
implementation 'com.job:droidnet:2.0.0'
implementation 'com.daimajia.easing:library:2.0#aar'
implementation 'com.daimajia.androidanimations:library:2.3#aar'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.0'
}
I cleaned the project and even rebuild it but the problem remains.
Deleting the existing apk from the debug folder and rebuilding the apk should work.
I'm adding Firebase Storage to upload images for my app, however after adding the dependency; I get the following errors:
My build.gradle(app) looks like this.
It is sadly not possible for me to use a higher SDK version as its a school project and we are limited to SDK 19...
Tried some multidex but couldn't make it work...
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.project.socker"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
def nav_version = "2.1.0"
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-auth:19.1.0'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.firebase:firebase-storage:19.1.0'
....\Socker\app\src\main\java\com\project\socker\MainActivity.java:
uses or overrides a deprecated API.
Recompile with -Xlint:deprecation for details.
OR
Cannot fit requested classes in a single dex file (# methods: 65924 > 65536)
Used a lower version like
implementation'com.google.firebase:firebase-storage:16.0.4'
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
Whenever i build my project in android studio it gives me the following error
Program type already present: com.google.android.gms.ads.identifier.AdvertisingIdClient$Info
below is my build.gradle file
lastly the line that has implementation 'com.android.support:design:27.0.0' also gives an error saying...
All com.android.support libraries must use the exact same version specification
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.iwatchug"
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-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.0.0'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services:7+'
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'
}
repositories {
google()
}
apply plugin: 'com.google.gms.google-services'
Remove the following line:
implementation 'com.google.android.gms:play-services:7+'
From the docs:
Note: Don't use the combined play-services target. It brings in dozens of libraries, bloating your application. Instead, specify only the specific Google Play services APIs your app uses.
You need to add specific google play services library, example:
implementation 'com.google.android.gms:play-services-vision:17.0.2'
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'