retrofit 2.0 xml simplexml converter issue while having retrolambda in gradle file - retrofit

Here is my gradle file
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.demo.sample"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
//Retrofit
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
//Retrofit support libraries
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
//compile 'com.squareup.retrofit2:converter-simplexml:2.0.0-beta4'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
//RxAndroid
compile 'io.reactivex:rxandroid:1.1.0'
//Explicit support for latest RxJava
compile 'io.reactivex:rxjava:1.1.0'
//Square dagger
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.dagger:dagger:1.2.2'
//Butterknife
compile 'com.jakewharton:butterknife:6.1.0'
//Picasso
compile 'com.squareup.picasso:picasso:2.3.3'
//Testing dependency
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:2.1.0'
testCompile 'org.mockito:mockito-core:2.0.23-beta'
}
If i un-comment line compile 'com.squareup.retrofit2:converter-simplexml:2.0.0-beta4' android studio throws nasty error at compile time
:app:transformClassesWithDexForDebug
trouble processing "javax/xml/XMLConstants.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
I'm not understanding what the error actually means. Also, is there a way to get around this problem.

Seem like Simple XML has transitive dependencies which are already included in Android. See https://github.com/square/retrofit/issues/1536.
We need to exclude three dependencies: stax:stax-api, stax:stax, and xpp3:xpp3.
I managed to achieve this by using this compile statement in gradle
compile ('com.squareup.retrofit2:converter-simplexml:2.0.0-beta4'){
exclude module: 'stax-api'
exclude module: 'stax'
exclude module: 'xpp3'
}

Related

JFrog REST api client app fails to build with missing org.apache.commons.* packages

We have a Java app that was built using 2017 version of JFrog java services jar. Today I am trying to rebuild it using latest jfrog lib. I see that the new services jar doesn't have org.apache.* packages in it.
This is how I built jfrog services jar.
Downloaded 2.8.6 source zip and expanded it
Upgraded gradle to latest and ran "gradle clean build -x test -x javadoc"
Then copied services/build/lib/*services-2.8.6.jar ONLY to my project lib folder
When I try to build, I see so many compilation errors. The old lib was called something like artifactory-java-client-ning-services-1.2.0-all.jar.
How do I build one like it?
Update on 11/6/20 after Dror responses below:
I changed the build strategy to point to jcenter to download and create uber jar with all the dependencies with gradle file like below. I am still running into missing classes.
Below is one of those errors:
error: package org.jfrog.artifactory.client.ArtifactoryClient does not exist
import org.jfrog.artifactory.client.ArtifactoryClient.ProxyConfig;
In Netbeans IDE that I am using, I can expand each package in a jar and see the classes in it. I don't see anything under org.jfrog.artifactory.client package. That is strange.
My build.gradle:
group 'org.jftog.example'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.13
repositories {
jcenter()
}
dependencies {
compile 'org.apache.commons:commons-collections4:4.4'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-services:+'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-api:+'
}
jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
Update on Nov 10th 2020:
I found that the artifactory sdk changed and I was using stale classes. I fixed those references in my classes to use newer SDK counterparts and the issues were gone.
I ended up using following gradle file to build everything I needed:
group 'artifactory-client-sdk'
version ''
apply plugin: 'java'
sourceCompatibility = 1.8
buildDir="${rootDir}/../out/artifactory_client_sdk"
def signbridge_lib="${rootDir}/../libs"
jar.baseName = 'artifactory-client-sdk'
repositories {
jcenter()
}
dependencies {
implementation 'ch.qos.logback:logback-classic:1.2.3'
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-services:+'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-api:+'
}
jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA','**/org/jfrog/example'
}
task copyJar(type: Copy) {
from jar // copies output of file produced from jar task
into "${signbridge_lib}"
}
build.finalizedBy copyJar
Thanks a lot to Dror for great pointers!
The sources of the Artifactory Java client can be found in the jfrog/artifactory-client-java GitHub repository.
The services module used to be built as an uber jar containing 3rd party dependencies. On Oct 2019 the build has changed to create a thin jar instead of an uber jar.
To solve you issue you can either:
Include the 3rd party dependencies of the service module when building you application
Revert the change in build.gradle and continue to build an uber jar
Instead of building from source, you can consume the artifact from jcenter where is it being published by JFrog. The artifacts are published together with Maven .pom files which contains all the required 3rd party dependencies (all of them are available in jcenter).
In addition, there is an example Github project which shows how to consume the client library using Maven or Gradle.

Gradle implementation vs compile in jar task

I can successfully use Gradle to compile a fat JAR, but having trouble running the JAR after recently switching from the "compile" dependency specification to the "implementation/api" specification. I have isolated that the problem occurs in only one of the two following cases. The application runs in either case inside IntelliJ.
first/problem:
dependencies {implementation 'no.tornado:tornadofx:1.7.18'}
second/works:
dependencies {compile'no.tornado:tornadofx:1.7.18'}
The JAR compiles in both cases. The problem appears when I attempt to start the first case JAR on the command line and it throws the following error.
C:\aaa_eric\code\testr\mic\build\libs>java -jar mic-1.0-snapshot.jar
Error: Could not find or load main class app.MyApp
Caused by: java.lang.NoClassDefFoundError: tornadofx/App
Here is the JAR task in build.gradle. Is it possible that the tornadofx dependency is available at compile time, but not at run time? Thanks for any help.
jar {
manifest {
attributes 'Main-Class': 'app.MyApp'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
Changing configurations.compile.collect to configurations.compileClasspath.collect fixed the problem for me.
I was having the same problem and stumbled across this in https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/ConfigurationContainer.html:
An example showing how to refer to a given configuration by name in
order to get hold of all dependencies (e.g. jars, but only)
apply plugin: 'java' //so that I can use 'implementation', 'compileClasspath' configuration
dependencies {
implementation 'org.slf4j:slf4j-api:1.7.26'
}
//copying all dependencies attached to 'compileClasspath' into a specific folder
task copyAllDependencies(type: Copy) {
//referring to the 'compileClasspath' configuration
from configurations.compileClasspath
into 'allLibs'
}
One thing to note is that configurations.compileClasspath.collect worked for me even when I was using the compile specification instead of implement.

Failed to capture fingerprint of input files for task ':app:preDebugBuild' property 'compileManifests' during up-to-date check

I'm setting firebase on my project and when I add inappmessaging-display lib this error appears:
Dependency resolved to an incompatible version:
Dependency(fromArtifactVersion=ArtifactVersion(groupId=com.google.firebase,
artifactId=firebase-messaging, version=17.3.2),
toArtifact=Artifact(groupId=com.google.firebase,
artifactId=firebase-iid), toArtifactVersionString=[17.0.2]) FAILURE:
Build failed with an exception.
What went wrong: Failed to capture fingerprint of input files for task ':app:preDebugBuild' property 'compileManifests' during
up-to-date check. In project 'app' a resolved Google Play services
library dependency depends on another at an exact version (e.g.
"[17.0. 2]", but isn't being resolved to that version. Behavior
exhibited by the library will be unknown.
Dependency failing: com.google.firebase:firebase-messaging:17.3.2 -> com.google.firebase:firebase-iid#[17.0.2], but fire base-iid version was 17.0.3.
The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art ifact
with the issue. -- Project 'app' depends onto
com.google.firebase:firebase-iid#17.0.3 -- Project 'app' depends
onto com.google.firebase:firebase-messaging#17.3.2 -- Project 'app'
depends onto com.google.firebase:firebase-ads#17.1.2 -- Project
'app' depends onto
com.google.firebase:firebase-inappmessaging-display#17.0.4 --
Project 'app' depends onto
com.google.firebase:firebase-analytics#16.0.6 -- Project 'app'
depends onto com.google.firebase:firebase-analytics-impl#16.2.4 --
Project 'app' depends onto
com.google.firebase:firebase-inappmessaging#17.0.4 -- Project 'app'
depends onto com.google.firebase:firebase-core#16.0.6 -- Project
'app' depends onto
com.google.firebase:firebase-measurement-connector-impl#17.0.4 --
Project 'app' depends onto com.google.firebase:firebase-config#16.1.3
-- Project 'app' depends onto com.google.firebase:firebase-crash#16.2.1 -- Project 'app' depends
onto com.google.firebase:firebase-abt#16.0.1 -- Project 'app'
depends onto com.google.firebase:firebase-perf#16.2.3 -- Project
'app' depends onto
com.google.android.gms:play-services-measurement-api#16.0.4
For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep endency
paths to the artifact. This error message came from the
google-services Gradle plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding
"googleServices { disableVersionCheck = false }" to your build.gradle
file.
project file
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath ('com.google.firebase:firebase-plugins:1.1.5')
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'com.gradle.build-scan' version '1.16'
}
ext {
support_library_version = '28.0.0' //use the version of choice
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myapp.pocapp"
minSdkVersion 25
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:animated-vector-drawable:$support_library_version"
implementation "com.android.support:exifinterface:$support_library_version"
implementation "com.android.support:cardview-v7:$support_library_version"
implementation "com.android.support:customtabs:$support_library_version"
implementation "com.android.support:support-media-compat:$support_library_version"
implementation "com.android.support:support-v4:$support_library_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_library_version"
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'
//Play services dependencies
implementation('com.google.android.gms:play-services-plus:15.0.1')
implementation('com.google.android.gms:play-services-gcm:15.0.1')
implementation('com.google.android.gms:play-services-maps:15.0.1')
implementation('com.google.android.gms:play-services-ads:15.0.1')
implementation('com.google.android.gms:play-services-location:15.0.1')
implementation('com.google.android.gms:play-services-analytics:16.0.3')
implementation('com.google.android.gms:play-services-basement:15.0.1')
implementation('com.google.android.gms:play-services-auth:16.0.0')
implementation('com.google.android.gms:play-services-drive:15.0.1')
//General google dependencies
implementation('com.android.installreferrer:installreferrer:1.0')
implementation('com.android.billingclient:billing:1.2')
//Firebase dependencies
implementation('com.google.firebase:firebase-core:16.0.6')
implementation('com.google.firebase:firebase-perf:16.2.3')
implementation('com.google.firebase:firebase-ads:17.1.2')
implementation('com.google.firebase:firebase-crash:16.2.1')
implementation('com.google.firebase:firebase-config:16.1.3')
implementation('com.google.firebase:firebase-messaging:17.3.2')
implementation('com.google.firebase:firebase-inappmessaging:17.0.4')
implementation('com.google.firebase:firebase-inappmessaging-display:17.0.4')
}
apply plugin: 'com.google.gms.google-services'
I already updated all libs to latest versions.
I am also facing same issue,
At finally got a Solution.
Please remove Cordova-plugin-firebase and
Use the latest major releases just by running: cordova plugin add cordova-plugin-firebase-lib
Simply follow the following link: https://www.npmjs.com/package/cordova-plugin-firebase-lib
Check your internet connection.
If you are connected,try to use a proxy server (using hotspot shield,PSiphone, etc.)
The problem was on firebase libs versions, Just update every lib to fix this.
cd android
./gradlew clean
try this

Flutter: Build errors for cloud_firestore: above version "0.7.4"

I have been trying to resolve a build issue for hours until I realise it is due to Flutter plugin cloud_firestore. Version 0.7.4 builds fine for both Android and iOS but anything above 0.7.4 like 0.8.2+1 will have errors such as:
CloudFirestorePlugin.java:160: error: cannot find symbol
query = query.whereArrayContains(fieldName, value);
^ symbol: method whereArrayContains(String,Object) location: variable query of type
Query
/dev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:598:
error: cannot find symbol
builder.setTimestampsInSnapshotsEnabled(
^ symbol: method setTimestampsInSnapshotsEnabled(Boolean) location: variable builder
of type Builder
/dev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:678:
error: cannot find symbol
return FieldValue.arrayUnion(toArray(readValue(buffer)));
^ symbol: method arrayUnion(Object[]) location: class FieldValue
/dev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:680:
error: cannot find symbol
return FieldValue.arrayRemove(toArray(readValue(buffer)));
^ symbol: method arrayRemove(Object[]) location: class FieldValue Note:
/Users/peterlumdev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java
uses unchecked or unsafe operations. Note: Recompile with
-Xlint:unchecked for details. 4 errors FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':cloud_firestore:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
* 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 11s Gradle task assembleDebug failed with exit code 1
I would like to use 0.8.2+1 cloud_firestore for both ios and Android because of the support of
await db.settings(timestampsInSnapshotsEnabled: true);
Appreciate some help here. Many Thanks!
There is a problem with google-services.json.
In my case, I was in the same situation while coding Firebase for Flutter on Google Codelabs. I put GoogleService-Info.plist in Xcode in the corresponding folder and put google-services.json in the corresponding folder in Adndroid Studio as well. iOS Simulator worked, but in Android Studio the window like the one below is displayed, then pressing the OK button and launching Android Emulator resulted in the corresponding error.
When coding from scratch and inserting the google-services.json file from the Finder instead of Android Studio, no error occurred.
It's not working because it is creating a gradle conflict. Version 0.7.3 of firestore is working because gradle tooling is updated at that version. Please refer changelog and also refer this answer for any other working versions of firebase products.
I feel you, I've also spent hours and hours trying to figure this out.
After building a SSCCE, and then applying the settings of that project to my project, and then some tweaking, I got my project working.
Although I adjusted more settings than I care to remember, these seem to have had the highest impact:
In pubspec.yaml:
# included two other common libraries others might use
cloud_firestore: 0.8.2+1
firebase_auth: 0.7.0
google_sign_in: 3.2.4
Explicitly disable these two features in android/gradle.properties :
android.useAndroidX=false
android.enableJetifier=false
Use these versions of dependencies in android/build.grade:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
And finally, use these settings in android/app/build.gradle:
android {
compileSdkVersion 27
...
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
...
}
...
}
...
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.1'
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 'com.android.support:multidex:1.0.3'
}
It's also worth noting that I downloaded the google-services.json file again (though that didn't have any effect just by itself).
Any combination of these settings might help you.

Facebook SDK import statement doesn't find classes

I've already read up on tons of variations of this problem, but I can't seem to get the import com.facebook. line to work in my application using Android Studio 2.0.
I have a main application and a library module, and I'm using the Facebook SDK in the library module. Here's my top project gradle:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And the gradle for my library:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.11.0'
}
Now, when I sync gradle, it does seem to build all of the intermediate stuff like it should. However when I try to do an import statement, the only options I get are:
import com.facebook.*
import com.facebook.R
No other options are available. If I try to do this:
import com.facebook.FacebookSdk
The word FacebookSdk is in red, because it can't find it.
I've been beating on this all morning long. I'm converting an old Eclipse project, but this started out as a brand new Android Studio project (not an import from an old Eclipse project). It seems as if there's another Facebook SDK floating around without any exports in it, but I'll be darned if I can't find it. I've also tried quite a few earlier versions of the Facebook SDK, and they all do the same thing.
Where in the heck am I going wrong here?
Answered my own question! Little did I know that you have to have a successful build BEFORE you can add the import statements. I had added compile 'com.facebook.android:facebook-android-sdk:4.11.0' then immediately tried to import com.facebook.FacebookSdk without doing a successful build first.
To be fair, step 6 of the Google quick start does say 'Build your project', but the importance of doing this before adding any SDK code kinda bounced off me.

Resources