New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to retrofit 2.0 #28

Closed
Alelak opened this Issue Oct 12, 2015 · 32 comments

Comments

@Alelak

Alelak commented Oct 12, 2015

As of retrofit 2.0 some classes (e.g. RetrofitError) has been removed.

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented Oct 12, 2015

Retrofit 2.0 has a completely new API that is not compatible with 1.X. Once Retrofit 2.0 is final we will investigate upgrading.

@Spoetnic

This comment has been minimized.

Spoetnic commented Oct 29, 2015

So what would be your suggestion for people that start now with retrofit, and want to include the twitter-kit? Since the retrofit homepage/documentation only shows 2.0.0.

@oliveiradev

This comment has been minimized.

oliveiradev commented Nov 2, 2015

@Spoetnic you have solution for this?

@felipecsl

This comment has been minimized.

felipecsl commented Nov 17, 2015

Please refer to this issue for a way to fix this

@felipecsl

This comment has been minimized.

felipecsl commented Nov 17, 2015

Also this is a duplicate of #25

@Spoetnic

This comment has been minimized.

Spoetnic commented Nov 17, 2015

Following the steps that @felipecsl posted, I created the following files, which I put in the project's 'libs' folder.
https://dl.dropboxusercontent.com/u/634035/retrofit_1.9.0%20and%20twitter_1.9.1%20libs.zip
Unzip this files to your 'libs' folder.
I build my own, because I had the original dependency:

compile('com.twitter.sdk.android:twitter:1.9.1@aar') {
    transitive = true;
}

And not just twitter-core, (which I assume @felipecsl had.

I didn't change anything to my root-build.gradle, but added the following to my (only) project-module-build.gradle (from @felipecsl 's solution (square/retrofit#1152)):

android {
    //For using both retrofit 1.x and 2.x
    packagingOptions {
        exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.properties'
        exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.xml'
    }
}

repositories {
    // this tells gradle to read the aar files from the libs directory
    // make sure you don't have maven { url 'https://maven.fabric.io/public' } here, since
    // you want to grab the files specifically from the libs folder and not from maven
    flatDir { dirs 'libs' }
//    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.digits.sdk.android:digits:1.9.1@aar'
    compile 'io.fabric.sdk.android:fabric:1.3.7@aar'
    compile 'com.twitter.sdk.android:tweet-composer:1.0.1@aar'
    compile 'com.twitter.sdk.android:tweet-ui:1.7.0@aar'
    compile 'com.twitter.sdk.android:twitter:1.9.1@aar'
    compile 'com.twitter.sdk.android:twitter-core:1.6.1@aar'
    compile(files('libs/retrofit-1.9.0.jar'))
}

NOTE: I used retrofit 1.9.0, instead of @felipecsl 's 1.8.0, because I do not actively use Digits.
I only needed the Initialisation that Fabric inserted in my app to work, combined with a SearchTimeline.
I did use the same jarjar rule, so If digits breaks in this zip, you could try the retrofit_1.8.0.jar from @felipecsl 's solution (square/retrofit#1152)

@stephenmcbride

This comment has been minimized.

stephenmcbride commented Nov 26, 2015

Could you show the full gradle file please @Spoetnic? Do you still have a regular gradle dependency on Retrofit 2.0? I'm trying to use your solution but I get a java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit/RestAdapter$Builder when I try to use the TweetTimelineListAdapter. Thanks

@Spoetnic

This comment has been minimized.

Spoetnic commented Nov 26, 2015

@stephenmcbride Here is my censored build.gradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

android {
    //For using both retrofit 1.x and 2.x
    packagingOptions {
        exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.properties'
        exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.xml'
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 50
        versionName "2.0"
    }

    productFlavors {
        X{
            applicationId '...'
        }
        Y{
            applicationId '...'
        }
        Z{
            applicationId '...'
        }

    }
}

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.20.1'
    }
}

repositories {
    maven { url "https://jitpack.io" }
    // this tells gradle to read the aar files from the libs directory
    // make sure you don't have maven { url 'https://maven.fabric.io/public' } here, since
    // you want to grab the files specifically from the libs folder and not from maven
    flatDir { dirs 'libs' }
}

dependencies {
    //Non-Gradle Support Libraries
    compile fileTree(include: ['*.jar'], dir: 'libs')

    //Google Support Libraries
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'

    //External Support Libraries
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.balysv.materialmenu:material-menu-toolbar:1.5.4'
    compile 'se.emilsjolander:stickylistheaders:2.5.2'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    compile('com.github.afollestad.material-dialogs:core:0.8.5.1@aar') {
        transitive = true
    }

    //    compile('com.twitter.sdk.android:twitter:1.9.1@aar') {
    //        transitive = true;
    //    }
    // Workaround for digits still depending on Retrofit 1.8.0
    // Revert once that's upgraded to 2.0.0
    // Steps followed to get this to work: https://github.com/twitter/twitter-kit-android/issues/28
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.digits.sdk.android:digits:1.9.1@aar'
    compile 'io.fabric.sdk.android:fabric:1.3.7@aar'
    compile 'com.twitter.sdk.android:tweet-composer:1.0.1@aar'
    compile 'com.twitter.sdk.android:tweet-ui:1.7.0@aar'
    compile 'com.twitter.sdk.android:twitter:1.9.1@aar'
    compile 'com.twitter.sdk.android:twitter-core:1.6.1@aar'
    compile files('libs/retrofit-1.9.0.jar')
}

Also, I have this in my proguard file: (I believe OKIO was part of Fabric)

# ------------------------------------------
# RETROFIT config
# ------------------------------------------

-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions

# ------------------------------------------
# FABRIC TWITTER config
# ------------------------------------------

-dontwarn com.squareup.okhttp.**
-dontwarn com.google.appengine.api.urlfetch.**
-dontwarn rx.**
-dontwarn retrofit.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

# ------------------------------------------
# OKIO config
# ------------------------------------------

-dontwarn okio.**
-keep class okio.** { *; }
@stephenmcbride

This comment has been minimized.

stephenmcbride commented Nov 26, 2015

Thanks @Spoetnic!

@Spoetnic

This comment has been minimized.

Spoetnic commented Dec 8, 2015

-- DELETED --
My bad, my (non-)issue had other causes.

@zsiegel

This comment has been minimized.

zsiegel commented Dec 10, 2015

As of a few days ago there is a SNAPSHOT maven lib that renames the package to retrofit2

If youd like you can use that to avoid this clashing.

add maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } to your repositories block and then reference com.squareup.retrofit2 instead of the old com.squareup.retrofit in your deps.

@jlubeck

This comment has been minimized.

jlubeck commented Dec 12, 2015

Thanks @zsiegel ! it worked like a charm

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented Dec 12, 2015

Announcement concerning new package name for Retrofit2: https://twitter.com/JakeWharton/status/675344652527083520

@jlubeck

This comment has been minimized.

jlubeck commented Dec 12, 2015

I couldn´t find in the announcement when that will kick in. Did you? Thanks for the heads up though!

@oliveiradev

This comment has been minimized.

oliveiradev commented Dec 15, 2015

@zsiegel Thanks

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented Jan 5, 2016

FYI: Retrofit2.0-Beta3 has been released with new package name. See: https://github.com/square/retrofit/releases/tag/parent-2.0.0-beta3

@ghiyatshanif

This comment has been minimized.

ghiyatshanif commented Mar 4, 2016

getting the same error, i'm using the beta4 of retrofit but still resulting the NoClassDefFoundError, can someone paste your working gradle setting, please

@Spoetnic

This comment has been minimized.

Spoetnic commented Mar 4, 2016

@ghiyatshanif, is your proguard is correct?

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented Mar 4, 2016

@ghiyatshanif we don't support retrofit2 yet. We will update our dependencies once the final version is released. In the mean time you can include both versions.

dependencies {
    compile('com.twitter.sdk.android:tweet-ui:1.9.1@aar') {
        transitive = true;
    }

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    compile 'com.squareup.okhttp:okhttp:2.7.4'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.4'
}
@AlexVPerl

This comment has been minimized.

AlexVPerl commented Mar 18, 2016

@efrohnhoefer I tried as per your suggestion but I still see the same problem.

I feel Proguard is to blame. Can you please post your proguard config?

Thanks.

@saran2somu

This comment has been minimized.

saran2somu commented Mar 18, 2016

Hi
@efrohnhoefer I tried above libraries with twitter log in button (TwitterLoginButton)

I have the error , logcat output

* java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit/RestAdapter$Builder;*
at com.twitter.sdk.android.core.internal.oauth.OAuthService.(OAuthService.java:50)
at com.twitter.sdk.android.core.internal.oauth.OAuth1aService.(OAuth1aService.java:74)
at com.twitter.sdk.android.core.identity.OAuthActivity.onCreate(OAuthActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6072)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.access$900(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:139)
at android.app.ActivityThread.main(ActivityThread.java:5298)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
Caused by: java.lang.ClassNotFoundException: Didn't find class "retrofit.RestAdapter$Builder" on path: DexPathList[[zip file "/data/app/com.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at com.twitter.sdk.android.core.internal.oauth.OAuthService.(OAuthService.java:50)
            at com.twitter.sdk.android.core.internal.oauth.OAuth1aService.(OAuth1aService.java:74)
            at com.twitter.sdk.android.core.identity.OAuthActivity.onCreate(OAuthActivity.java:69)
            at android.app.Activity.performCreate(Activity.java:6072)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
            at android.app.ActivityThread.access$900(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:139)
            at android.app.ActivityThread.main(ActivityThread.java:5298)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
Suppressed: java.lang.ClassNotFoundException: retrofit.RestAdapter$Builder
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented Mar 18, 2016

@AlexVPerl I am not using proguard. But this hypothesis can be tested by disabling proguard. May also just require a clean build.

@saran2somu Can you share a sample project where this error is reproducible?

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented Mar 18, 2016

Here is my current build.gradle for my test app:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.twitter.efrohnhoefer.crashreportingtest01"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'

    compile('com.twitter.sdk.android:twitter:1.13.0@aar') {
        transitive = true;
    }

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.okhttp:okhttp:2.7.4'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.4'
}
@chentengming

This comment has been minimized.

chentengming commented Mar 29, 2016

@efrohnhoefer It not work,who can tell me how to do,i just want to share content from my app to twitter.it is so difficult!

@extmkv

This comment has been minimized.

extmkv commented Apr 13, 2016

Can you support Retrofit 2?

@sidiqpermana

This comment has been minimized.

sidiqpermana commented May 2, 2016

retrofit now has its stable version, are you guys planned to update this lib using retrofit 2.0?, i've been trying above soluutions but still getting the same error

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented May 2, 2016

@sidiqpermana It would be helpful if you provided a reproducible test case since I am unable to reproduce the above error. This is what my Gradle file currently looks like for my tests.

    compile('com.twitter.sdk.android:twitter:1.13.1@aar') {
        transitive = true;
    }

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.okhttp:okhttp:2.7.4'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.4'
@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented May 2, 2016

I cannot comment on exact timelines but Retrofit 2.0 support is something currently being worked on.

@PiotrWpl

This comment has been minimized.

PiotrWpl commented Jun 8, 2016

Any updates? :)

@yshrsmz

This comment has been minimized.

yshrsmz commented Aug 12, 2016

@efrohnhoefer Congratulations! Any plan to release source code?

@efrohnhoefer

This comment has been minimized.

Contributor

efrohnhoefer commented Aug 13, 2016

@yshrsmz Source will be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment