tinycreative / react-native-intercom

React Native wrapper for Intercom.io
MIT License
407 stars 280 forks source link

Update to Intercom SDK 9 #432

Closed nbokmans closed 3 years ago

nbokmans commented 3 years ago

I was unable to build my project anymore in XCode 12.5 due to the Intercom.framework (SDK 8) being incompatible. Luckily the version bumps were easy to do (no breaking changes in SDK 8 -> 9) and I thought this might be useful to others.

For now, I've updated my package.json to use react-native-intercom as such:

    "react-native-intercom": "https://github.com/nbokmans/react-native-intercom",

You will need to re-link the Intercom.xcframework to update to SDK 9. Refer to the steps found here: https://developers.intercom.com/installing-intercom/docs/ios-installation#section-option-3-install-intercom-manually

Thank you!

erkie commented 3 years ago

On a new install this worked flawlessly. No need to manually install or link anything.

erkie commented 3 years ago

Unfortunately it seems that Intercom SDK for Android has incompatible versions of okhttp3, so I ended up having to downgrade for Android. Were you able to fix that?

nbokmans commented 3 years ago

@erkie Sorry for the delayed response. I hadn't properly tested on Android and I had assumed it would work like it did on iOS since there were no major changese.

What worked for me is the following. In my src/android/app/build.gradle, I changed this line (which I added according to this repo's README):

implementation 'io.intercom.android:intercom-sdk-base:5.+'

to

implementation 'io.intercom.android:intercom-sdk-base:9.+'

When I tried using any Intercom features in my app on Android, it would indeed crash, with what I expect is the same exception you were getting:

java.lang.NoSuchMethodError: No virtual method toString(Z)Ljava/lang/String; in class Lokhttp3/Cookie; or its super classes (declaration of 'okhttp3.Cookie' appears in com.app...

For that problem, I found the following SO question where they suggest to add the following dependency:

implementation("com.squareup.okhttp3:okhttp-urlconnection:4.4.1")

I added this dependency under the io.intercom.android-sdk-base dependency. After that, I rebuilt my project, and everything worked properly.

Disclaimer I am not entirely sure of the implications of adding this dependency on okhttp-urlconnection:4.4.1 - it didn't seem to break anything, but it does seem like a bandaid solution.

michaelknoch commented 3 years ago
configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.12.+'
} 

does also solve the runtime crash. I noticed that react native and a bunch of react native libraries are referencing okhttp:3.12.x versions. The downgrading approach might be safer, but I don't think it makes a huge difference at all. @nbokmans

michaelknoch commented 3 years ago

I also think we have to add the following block to the build.gradle, otherwise I run into "desugaring issues" when building for release. I don't exactly know where this is coming from, but it does only happen when updating intercom to version 9. If this makes sense to you, would be great if you can add it to your pr @nbokmans (I am already referencing your fork in my project =P)

android {
    ....
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Failed to transform intercom-sdk-base-9.1.0.aar (io.intercom.android:intercom-sdk-base:9.1.0) to match attributes {artifactType=android-dex, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingTransform: /Users/michaelknoch/.gradle/caches/transforms-2/files-2.1/0168afdfe2154c6f1ebd46fdbc2c5ba2/jars/classes.jar.
         > Error while dexing.
           The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
           android {
               compileOptions {
                   sourceCompatibility 1.8
                   targetCompatibility 1.8
               }
           }
           See https://developer.android.com/studio/write/java8-support.html for details. Alternatively, increase the minSdkVersion to 26 or above.
nbokmans commented 3 years ago

@michaelknoch I've got that part as part of my app's android/app/build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: false
]

apply from: "../../node_modules/react-native/react.gradle"

project.ext.vectoricons = [
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    //...
}

With this place, I don't get the error you describe.

I do remember having to npx jetify (https://github.com/mikehardy/jetifier) but I also did that prior to this Intercom upgrade.

Could you check and see if that fixes the issue for you as well? I feel like the app is the proper place for the compileOptions settings, and should not be part of the library, because that would make the library "opinionated" to jdk 1.8 I think

michaelknoch commented 3 years ago

I was able to workaround the build issues by adding the following snippet in my root build.gradle file:

subprojects {
    afterEvaluate {project ->
        // prevents dexing errors
        if (project.name == "react-native-intercom") {
            android.compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
            }
        }
    }
}

I don't really understand why this is needed. The regular build works, but building the testing apk always fails because of the Java 8 bytecode` error.

michaelknoch commented 3 years ago

@nbokmans @erkie is there any more effort needed to get this in?

michaelVictoriaDev commented 3 years ago

I having a same issue, I try and tested in my physical phone and emulator in android but Im having app crash,,

the screenshot came from adb logcat, I think that is causing the app crash.

image

browniefed commented 3 years ago

react-native-intercom@20.0.0

michaelVictoriaDev commented 3 years ago

Intercom in android is now working , 1 last thing that din't follow is the

implementation("com.squareup.okhttp3:okhttp-urlconnection:4.4.1") Im having crash app and saw in adb logs that is the cause of the app crash,

Thanks @michaelknoch