Duplicate class android.support.v4.app.RemoteActionCompatParcelizer found - java

I received a jar files for one of the application SDKs. I need to extend this SDK to include my features. One of the jar file include android and androidx packages.
The steps I followed to integrate the sdk jar files to my base brand new application, I added jar files under libs directory of app. Then right click the jar file and clicked "add as library".
I went to basicActivity and tried to import of the files from the SDK jar file, it was not detected. So, I added dependency in the libs folder, then build the application (Build -> Rebuild Project). Then so many of the duplicate class error came like the below,
Duplicate class android.support.v4.app.RemoteActionCompatParcelizer found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and jetified-main (main.jar)
with advices from other threads, I added exclude group
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.bo.ri"
minSdk 21
targetSdk 32
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 JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations {
all { // You should exclude one of them not both of them
exclude group: "androidx.annotation", module: "annotation"
exclude group: "androidx.fragment", module: "fragment"
exclude group: "androidx.activity", module: "activity"
exclude group: "androidx.core", module: "core"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
The duplicate class errors started fading, however, with subsequent builds, I get the following error. How to fix this?
ERROR:D:\Android.gradle\caches\transforms-3\19075c4677e37e538c54d7f745fc8af4\transformed\appcompat-1.4.1\res\color\abc_btn_colored_text_material.xml:22: AAPT: error: attribute alpha (aka com.bo.ri:alpha) not found.
Hint: I cleared caches within .gradle folder as well

Related

Duplicate class error when trying to add firebase dependencies in AndroidStudio

I'm trying to develop an app in AndroidStudio and i'm using cloud firestore as database. I'm having some issues when i try to add both 'com.google.firebase:firebase-admin:6.11.0'and 'com.google.firebase:firebase-core:17.0.0 dependencies. I get these messages when I try to make the project:
Duplicate class com.google.firebase.FirebaseAppLifecycleListener found in modules firebase-admin-6.11.0.jar (com.google.firebase:firebase-admin:6.11.0) and firebase-common-18.0.0-runtime.jar (com.google.firebase:firebase-common:18.0.0)
Duplicate class com.google.firebase.FirebaseException found in modules firebase-admin-6.11.0.jar (com.google.firebase:firebase-admin:6.11.0) and jetified-play-services-basement-17.0.0-runtime.jar (com.google.android.gms:play-services-basement:17.0.0)
Duplicate class com.google.firebase.FirebaseOptions found in modules firebase-admin-6.11.0.jar (com.google.firebase:firebase-admin:6.11.0) and firebase-common-18.0.0-runtime.jar (com.google.firebase:firebase-common:18.0.0)
Duplicate class com.google.firebase.FirebaseOptions$1 found in modules firebase-admin-6.11.0.jar (com.google.firebase:firebase-admin:6.11.0) and firebase-common-18.0.0-runtime.jar (com.google.firebase:firebase-common:18.0.0)
Duplicate class com.google.firebase.FirebaseOptions$Builder found in modules firebase-admin-6.11.0.jar (com.google.firebase:firebase-admin:6.11.0) and firebase-common-18.0.0-runtime.jar (com.google.firebase:firebase-common:18.0.0)
Duplicate class com.google.firebase.iid.FirebaseInstanceId found in modules firebase-admin-6.11.0.jar (com.google.firebase:firebase-admin:6.11.0) and firebase-iid-19.0.0-runtime.jar (com.google.firebase:firebase-iid:19.0.0)
Go to the documentation to learn how to Fix dependency resolution errors.
I have tried with some other versions, older and newer but got the same problem. Anybody has any idea how to solve this? Thanks a lot. Here's my app gradle code
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "br.com.valorinveste.nextmobilefx"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
packagingOptions {
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/io.netty.versions.properties'
}
multiDexEnabled true
}
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.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// implementation 'com.google.firebase:firebase-analytics:17.0.0'
implementation 'com.google.firebase:firebase-admin:6.11.0'
implementation 'com.google.firebase:firebase-core:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
and the project gradle code
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.3'
// 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
}

Gradle migration 3.1.4 -> 3.5.1; :app module doesn't compile; ClassNotFoundException: Didn't find class on path: DexPathList

I have two applications where I face the same issue while trying to update project target API from 27 to 29. To do this, first I need to update Gradle plugin at least to 3.2.+.
Project is building fine with 3.1.4, but as soon as I rise Gradle plugin to:
classpath 'com.android.tools.build:gradle:3.5.1
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
(Same error with 3.2.1 and higher)
I see next RunTime exception:
Process: com.my.app, PID: 29804
java.lang.RuntimeException: Unable to instantiate application com.my.app: java.lang.ClassNotFoundException: Didn't find class "com.my.app" on path: DexPathList[[zip file "/data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/lib/x86, /data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/base.apk!/lib/x86, /system/lib]]
A problem that :app module source code is not compiled at all
(I can create manual compilation error and run will be still successful)
The same in both application.
What I tired:
I checked generated DEX files in the APK, source code is not there;
I create a new project with 3.5.1 plugin - it works fine;
Tried to delete gradle and .idea folders;
Tried to to clean and invalidate cache
Migrated project to AndroidX;
Added multiDexEnabled true - it was working without it before, anyway;
Copied dependencies to a new Project - works fine;
Added: to gradle.properties android.useAndroidX=true android.enableJetifier=true
My build files:
TOP level
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:6.0.0"
classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.31.1'
// 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/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Application:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.my.app"
minSdkVersion 21
targetSdkVersion 29
versionCode 2
versionName "1.01"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
ext.anko_version='0.10.5'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.facebook.fresco:fresco:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.0'
implementation "org.jetbrains.anko:anko-sdk21:$anko_version"
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
implementation "org.jetbrains.anko:anko-constraint-layout:$anko_version"
implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"
implementation "org.jetbrains.anko:anko-cardview-v7:$anko_version"
implementation 'com.r0adkll:slidableactivity:2.0.6'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
kapt "io.realm:realm-annotations-processor:5.9.0"
}
apply plugin: 'com.google.gms.google-services'
Note: another project has different set of dependencies still face the same issue
Why source code is not added to APK after migration to newer Gradle while working fine on the old one?
Update 1
Problem appear as soon as I update project to Gradle 3.2+
Update 2
Build folder doesn't contain class folder and class files
Update 3
Source code from :app module doesn't compile even tho it is in the settings.gradle file; I can create build error in any .java file and run will be executed successfully
I found an issue:
One of my packages name vas cvs - seems it is after Gradle 3.2.+ it is reserved word.

Cannot resolve module dependency after updating to Android Studio 3.2.1

After upgrading to AS 3.2.1, I get this gradle sync error:
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve project :androidlib_abc.
my app gradle.build:
apply plugin: 'com.android.application'
allprojects {
repositories {
// The order in which you list these repositories matter.
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "de.gpx.android.rtk"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
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'
compile project(path: ':androidlib_abc')
}
my androidlib_abc gradle.build file:
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 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 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
The "Open File" link in the error message points to the app gradle.build file. When I remove the line
compile project(path: ':androidlib_abc')
Then I can sync the grade project, but I cannot compile and use any package from that library (cannot resolve classes etc.)
I wish I didn't do the update... ("Never change a running system" -_-)
Any ideas how to fix?
UPDATE:
I removed the module from the project and then reimported it. Then everything worked fine! BUT: The module directory is copied into my project directory (usual behaviour). However, I need the module directory to be one level higher, in the same directory as the project directory is. This way, I could share the module with different projects without having duplicates and synchronizing work which saves me a lot of time (in fact I cannot work with multiple projects otherwise).
I used to use this settings.gradle file:
include ':app', ':androidlib_abc'
project(':androidlib_abc').projectDir = new File(rootProject.projectDir, '../androidlib_abc ')
which worked perfectly before AS 3.2.1
Now, after I successfully imported the module again and moved the module directory one level up and changed the settings.gradle file to this again, I get the unable-to-resolve-dependency error again :'-(
UPDATE2:
Using another constructor without the argument rootProject.projectDir allowed me to do the gradle sync.
include ':app', ':androidlib_abc'
project(':androidlib_abc').projectDir = new File('../androidlib_abc')
The library is finally listed on the left side!
However, a new issue came up. No classes/methods/fields etc. defined in the modul can be resolved. Not even in classes within the module itself although they are even in the same directory (package)... Cleaning and Rebuilding didn't help. Strange thing is, that building succeeds and I can apparently even install the app on my device and have it run without any exceptions...!? So is this just an IDE bug maybe?
UPDATE3
I deleted the .gradle and .idea directory and restarted AS. Everything's fine now B-)
try building androidlib_abc once .are you able to see this library in the side menu ?.
It could be that this particular library is not imported properly

Program type already present error

Although many similar questions exist, I checked the answers to all and none of them worked for me!
Here is the error I'm facing while compiling the code:
Program type already present: android.support.v4.app.BackStackRecord$Op
Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackRecord$Op, sources=[Unknown source file], tool name=Optional.of(D8)}
Here is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.narsun.grocery"
minSdkVersion 21
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'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.github.sd6352051.niftydialogeffects:niftydialogeffects:1.0.0#aar'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup:android-times-square:1.6.5#aar'
implementation 'com.daimajia.slider:library:1.1.5#aar'
implementation 'com.astuetz:pagerslidingtabstrip:1.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.myinnos:AwesomeImagePicker:1.0.2'
implementation 'com.github.ratty3697:android-smart-animation-library:1.6'
implementation 'com.github.zcweng:switch-button:0.0.3#aar'
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation 'com.google.android.exoplayer:exoplayer:2.6.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.10'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
}
You can tell me if there is anything else to add to understand what I'm doing or where I'm wrong.
In case anyone comes here with a similar issue. In my case it was because I had included an appcompat JAR file in the libs folder as well as having implementation 'com.android.support:appcompat-v7:26.0.0' in my gradle file.
When I removed the JAR file, that fixed my issue.
Probably the packages versions are not compatible. Try downgrading com.android.support packages, namely appcompat
so - implementation 'com.android.support:appcompat-v7:27.0.1'
I want to share how you can understand the error message.
First method, check your dependencies in build.gradle:
In this case, if I tried to remove that implementation, the error gone.
Second method, Check libs folder of your app which included .jar files:
In this case, if I tried to move that .jar to somewhere else, the error gone.
For the info for other who will face the same error, I was able to solve my problem by removing the following library from my gradle file:
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
This was the library creating issues for me. Thanks
I'm including a custom aar in my app/libs folder, and I correctly added the flatLib object to the root build.gradle, but incorrectly added the '*.aar' to the fileTree implementation in the app/build.gradle:
build.gradle
allprojects {
repositories {
...
flatDir {
dirs 'libs'
}
}
}
app/build.gradle
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'])
^^^
BAD

Getting error "package lombok doesn't exist" with Android Studio 3 RC2

I am getting the following error when trying to compile the project:
error: package lombok does not exist
And others stating that all the annotations from it can't be found.
I don't see errors in code before compiling and I didn't have this error while I was using Android Studio 3 RC1.
Here are my gradle scripts:
Project level:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
// 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
}
App module level:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.mk.forum"
minSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
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.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 (':util')
compile project (':forum_core')
compileOnly 'org.projectlombok:lombok:1.16.18'
annotationProcessor 'org.projectlombok:lombok:1.16.18'
compile group: 'com.github.javafaker', name: 'javafaker', version: '0.13'
}
I've got modules too, but I think it isn't important.
I hope it is because of compileOnly annotation. Here is the doc:
blog.gradle.org/introducing-compile-only-dependencies
Dependencies required at compile time but never required at runtime, such as source-only annotations or annotation processors;
Dependencies required at compile time but required at runtime only when using certain features, a.k.a. optional dependencies;
Dependencies whose API is required at compile time but whose implementation is to be provided by a consuming library, application
or runtime environment.
It might be related to jdk9. I know that the combination of IntelliJ, lombok 1.16.18 and jdk9 currently doesn't work. But that does not explain your error message. We expect that we can release 1.16.20 within a few days (maybe tonight) that addresses this problem.
Disclosure: I am a lombok developer.

Categories