Error [duplicateplatformclasses] while building app in release mode - java

After updating Android Studio and updated GDAA to Google Drive REST API as GDAA is deprecated, but now I can not build my app in release mode which had no issues before. Here is the complete error message:
org.gradle.api.GradleException: Lint found fatal errors while assembling a release target. To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
And in the lint-results-release-fatal.xml file I get these messages:
'commons-logging' defines classes that conflict with classes now
provided by Android. Solutions include finding newer versions or
alternative libraries that don't have the same problem (for example,
for httpclient use HttpUrlConnection or okhttp instead), or
repackaging the library using something like jarjar.
'httpclient' defines classes that conflict with classes now provided
by Android. Solutions include finding newer versions or alternative
libraries that don't have the same problem (for example, for
httpclient use HttpUrlConnection or okhttp instead), or repackaging
the library using something like jarjar.
Here is my gradle dependencies:
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:support-core-utils:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-ads:17.1.3'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
implementation('com.google.api-client:google-api-client-android:1.26.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.apis:google-api-services-drive:v3-rev136-1.25.0') {
exclude group: 'org.apache.httpcomponents'
}
}
I tried this and this but no luck.

After trying all other solutions with no luck, I suddenly discovered that this version of Android Studio 3.3.2 does not detect libraries which are out of date and found that the library causing the problem was this:
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
As this is the suspected library from this question.
I simply updated this library to the latest version which is this at the moment:
implementation 'com.google.http-client:google-http-client-gson:1.28.0'
And the problem was solved.
I post this question and give answer just because I could not find the right answer and for those struggling with the same problem could be the right solution.

Related

Gradle incompatibility with admob [duplicate]

This question already has answers here:
All com.android.support libraries must use the exact same version specification
(54 answers)
Closed 4 years ago.
I'm trying to add a banner add to a new app of mine and I've hit a roadblock adding the Gradle dependencies. I've been following the Admob tutorial on how to do it Admob Get Started Link
What I'm trying to use is the following
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.3'
implementation 'com.google.android.gms:play-services-ads:17.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'}
However the line with "appcompat-v7:27.1.1" gets underlined with the following message:
All com.android.support libraries must use the exact same version
specification, Found version 27.1.1, 26.1.0. Examples include
com.android.support:animated-vector-drawable:27.1.1
andcom.android.supports:customtabs:26.1.0
This underline warning only shows up when I add in the dependency for admob, specifically:
implementation 'com.google.android.gms:play-services-ads:17.0.0'
How/what should I be doing to fix this? I was testing this out earlier in the week and I didn't have any errors, the only thing I've added since then is permissions for phone vibration which I can't imagine has any effect. My app crashes on the opening screen
The issue is happening because there are two different versions of support libraries sync one by ads and another by app compat
To solve the issue use
configurations.all
{ resolutionStrategy.force 'com.android.supports:customtabs:27.1.1'
resolutionStrategy.force 'com.android.support:animated-vector-drawable:27.1.1'
 }
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']
........
Have you tried adding the library with the old version, but with new version??
com.android.support:customtabs:26.1.0 is your error so you need to add this:
implementation "com.android.support:customtabs:27.1.1"
It's an confusing error because you are not directly using this library, but more of the libraries you use, depend on this one, so you have to explicitly set which version to use

Dependencies conflict on app release APK, but not debug?

I have been tinkering with my code for a few days now, and I cannot get Gradle to assemble a signed APK for me (following the error code instructions will result in a successful build, but my Google Calendar API fails).
dependencies {
// commented stuff is no longer used or commented for some other reason.
//compile 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
// Dont know whats up with these errors above. ^
// they seem to work even though they are "incompatible"
implementation fileTree(include: ['*.jar'], dir: 'libs')
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.google.code.findbugs:jsr305:3.0.1'
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude module: 'guava-jdk5'
//exclude group: 'org.apache.httpcomponents'
}
implementation 'com.android.support:multidex:1.0.3'
//implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.android.support:cardview-v7:28.0.0'
//implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:28.0.0'
implementation 'com.bartoszlipinski.constraint:staggeredanimationgroup:1.0.0'
implementation 'com.android.support:transition:28.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.3'
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.1'
implementation 'com.google.firebase:firebase-core:16.0.3'
/*Make sure these are always updated to the newest versions.*/
implementation('com.google.oauth-client:google-oauth-client-jetty:1.23.0') {
exclude module: 'guava-jdk5'
}
implementation('com.google.apis:google-api-services-calendar:v3-rev305-1.23.0') {
exclude module: 'guava-jdk5'
}
//implementation 'pub.devrel:easypermissions:0.3.0'
implementation 'com.google.http-client:google-http-client-jackson:1.15.0-rc'
//implementation 'com.google.android.gms:play-services-auth:16.0.0'
These are my dependencies from my Gradle files.
Ignore the error on 'com.android.support:support-vector-drawable:28.0.0' because its fine; I just can't get my APK to assemble signed; and when it's forced, my Google Calendar code does not return events.
Executing tasks: [:app:assembleRelease]
Could not find google-services.json while looking in [src/nullnull/debug, src/debug/nullnull, src/nullnull, src/debug, src/nullnullDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/nullnull/release, src/release/nullnull, src/nullnull, src/release, src/nullnullRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
:app:checkReleaseClasspath
:app:preBuild UP-TO-DATE
:app:preReleaseBuild
:app:compileReleaseAidl NO-SOURCE
:app:compileReleaseRenderscript UP-TO-DATE
:app:checkReleaseManifest UP-TO-DATE
:app:generateReleaseBuildConfig UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:app:mainApkListPersistenceRelease UP-TO-DATE
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources UP-TO-DATE
:app:processReleaseGoogleServices
Parsing json file: C:\Users\Dylan\Documents\ClarenceFultonSecondary\app\google-services.json
:app:mergeReleaseResources
:app:createReleaseCompatibleScreenManifests UP-TO-DATE
:app:processReleaseManifest
:app:splitsDiscoveryTaskRelease UP-TO-DATE
:app:processReleaseResources
:app:generateReleaseSources
:app:javaPreCompileRelease
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileReleaseJavaWithJavac
:app:compileReleaseNdk NO-SOURCE
:app:compileReleaseSources
C:\Users\Dylan\Documents\ClarenceFultonSecondary\app\build.gradle: Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
C:\Users\Dylan\Documents\ClarenceFultonSecondary\app\build.gradle: Error: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
Explanation for issues of type "DuplicatePlatformClasses":
There are a number of libraries that duplicate not just functionality of
the Android platform but using the exact same class names as the ones
provided in Android -- for example the apache http classes. This can lead
to unexpected crashes.
To solve this, you need to either find a newer version of the library which
no longer has this problem, or to repackage the library (and all of its
dependencies) using something like the jarjar tool, or finally, rewriting
the code to use different APIs (for example, for http code, consider using
HttpUrlConnection or a library like okhttp).
2 errors, 0 warnings
:app:lintVitalRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
* 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 31s
This is what my lint report says:
Duplicate Platform Classes
../../build.gradle: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.
../../build.gradle: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.
Add the following code in app/build.gradle.
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
}

Cannot resolve symbol 'FloatingActionButton'

Recently I have downloaded a code from GitHub and synced it with my android studio. I have faced lots of errors and issues while doing so and somehow fixed most of them. However, the last issue I'm stuck at right now is that my android studio cannot find the class FloatingActionButton as you can see in this screenshot
It is to be noted that earlier many other classes, including 'AppCompatActivity' could not be resolved. Changing the dependencies to following solved the issue
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.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'
}
But even after changing dependencies, clean building the project, doing 'Invalidate Caches / Restart...', the problem with 'FloatingActionButton' is still there.
You can check the repository here
And this is the java code of the activity where the error is occurring
The FloatingActionButton is in the design library.
Add this line to your dependencies:
implementation 'com.android.support:design:27.1.1'
This post also has more general info about FloatingActionButton: FloatingActionButton example with Support Library
#Sub 6 Resources already answered this question wholly but I want to add a bonus tip. If you already added implementation 'com.android.support:design:27.1.1' to your code and the compiler can't still resolve the FloatingActionButton class, simply rebuild your project. A colleague and I recently had this same problem while the dependency was already there and a simple rebuild solved it all.
Update for AndroidX:
The answer of #Sub 6 Resources was perfect before androidX was introduced. Now, it is better to include the following dependency instead of the accepted answer's dependency:
implementation 'com.google.android.material:material:1.6.1'
NOTE: it might not be the latest version by the time you are reading this.

Cannot resolve symbol AndroidSchedulers

I'm using version 2.0.0 of RxJava, and it seems like I have no access to AndroidSchedulers. I'm unable to get access to mainthread through RxJava
AndroidSchedulers class is a part of RxAndroid library. Add it to your app's build.gradle:
before Gradle v3.0:
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
since Gradle v3.0:
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
Go back to Old Versions:
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
Then to the Newer Version:
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.1'
Sounds Weird but it works
I had same problem. You cannot call AndroidSchedulers with RxJava3. I think this is a bug. They need to fix it.
You need to add they on your dependencies of gradle:
//RxAndroid
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
//RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
def rxJavaVersion = '2.1.1'
//Add to dependencies the following libraries
dependencies {
implementation "io.reactivex.rxjava2:rxandroid:$rxJavaVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
}
Now you can use RX 3 by adding the below dependency
implementation "io.reactivex.rxjava3:rxandroid:$version"
get the version from this link : https://github.com/ReactiveX/RxAndroid

Exclude Package From Gradle Dependency

I'm experiencing an issue where multiple versions of the same class are showing up in my classpath. The class in question is javax.ws.rs.core.UriBuilder. The version I want to use is brought in by javax.ws.rs:javax.ws.rs-api:2.0.1. However, we also use the Jira rest client library which has a dependency on the older version of jersey (com.sun.jersey:jersey-core) which has included the java.ws packages bundled in it's jar.
Here is an example snippet from the build file:
dependencies {
compile 'com.atlassian.jira:jira-rest-java-client-core:2.0.0-m31'
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
compile 'org.glassfish.jersey.core:jersey-client:2.17'
}
I can't remove com.sun.jersey:jersey-core as it uses different package name from the new version and would cause class def not found exceptions in the Jira client.
As far as I can tell, my options at this point are:
Revert to using Jersey 1.x and it's implementation of jsr311
Somehow have gradle exclude the javax.ws package from the old jersey client.
I'd like to keep using the newer version of jersey so #2 would be my ideal solution but I'm not sure if it's even possible. Does anyone know how to go about this? If that's not possible, I'm open to other suggestions.
You can exclude an transitive dependency module like this:
compile ('org.glassfish.jersey.core:jersey-client:2.17') {
exclude group: 'javax.ws.rs'
exclude module: 'javax.ws.rs-api'
}
ref: 50.4.7 here
I found out that com.sun.jersey:jersey-core:1.19 doesn't bundle the javax.ws.rs class files and instead lists them as a compile-time dependency. Adding this snippet to my build.gradle fixed the issue.
configurations.all {
resolutionStrategy {
// For a version that doesn't package javax.ws
force 'com.sun.jersey:jersey-core:1.19'
}
}
exclude the group and module as below.
Ex :
implementation('org.apache.httpcomponents:httpclient:4.5.13') {
exclude group: 'commons-codec', module: 'commons-codec'
}

Categories

Resources