TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.2k stars 2.9k forks source link

detached Expo android app (version 30) okhttp3 problem #1236

Closed cheolhow closed 2 years ago

cheolhow commented 6 years ago

Current behavior

when detached Expo android app build, error: cannot find symbol class JavaNetCookieJar at

node_modules/react-native-video/android-exoplayer/src/main/java/com/brentvatne/exoplayer/DataSourceUtil.java

Reproduction steps

  1. ejected with expokit (version 30) app (made by exp init)
  2. install react-native-video (npm install and react-native link)
  3. open android studio, sync gradle, run app and build failed.

Expected behavior

build complete

image

I think this error is caused by using different version of okhttp3. I have found an issue with similar problem.

https://github.com/expo/expo/issues/561

The version of okhttp3 found in my app / build.gradle was 3.4.1. And the okhttp version of android-exoplayer that react-native-video is using seems to be 2.8.2.

cobarx commented 6 years ago

The 2.8.2 you're seeing is the OkHTTP extension for ExoPlayer, it corresponds to the version of ExoPlayer being 2.8.2. We use OkHTTP 3.11.0 for the actual OkHTTP implementation.

See if you can set your app to use 3.11.0, I expect that will fix it.

cheolhow commented 6 years ago

@cobarx I changed the version of okhttp3 to 3.11.0, but the same error occurred. Here is my build.gradle file.

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

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

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

android {
  compileSdkVersion 27
  buildToolsVersion '27.0.3'

  defaultConfig {
    applicationId 'com.tagall.tagmusic'
    targetSdkVersion 26
    versionCode 1
    versionName '1.0.0'
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    // Deprecated. Used by net.openid:appauth
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'host.exp.exponent'
    ]
  }
  dexOptions {
    javaMaxHeapSize System.getenv("DISABLE_DEX_MAX_HEAP") ? null : "8g"
  }

  flavorDimensions 'minSdk', 'remoteKernel'
  productFlavors {
    devKernel {
      dimension 'remoteKernel'
    }
    prodKernel {
      dimension 'remoteKernel'
    }
    devMinSdk {
      dimension 'minSdk'
      // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
      // to pre-dex each module and produce an APK that can be tested on
      // Android Lollipop without time consuming dex merging processes.
      minSdkVersion 21
    }
    prodMinSdk {
      dimension 'minSdk'
      minSdkVersion 19
    }
  }
  buildTypes {
    debug {
      debuggable true
      ext.enableCrashlytics = false
    }
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      zipAlignEnabled true
    }
  }
  signingConfigs {
    debug {
      storeFile file('../debug.keystore')
    }
  }
  lintOptions {
    abortOnError false
  }
  packagingOptions {
    pickFirst "**"
  }
  configurations.all {
    resolutionStrategy.force 'com.android.support:design:27.1.0'
  }
}

// Don't use modern jsc-android since it still has some critical bugs that
// crash applications when the string for the JS bundle is loaded and when
// locale-specific date functions are called.
// configurations.all {
//   resolutionStrategy {
//     force 'org.webkit:android-jsc:r216113'
//   }
// }

apply from: 'expo.gradle'

dependencies {
    compile project(':react-native-video')
  implementation fileTree(dir: 'libs', include: ['*.jar'])

  implementation 'com.android.support:multidex:1.0.1'

  // Our dependencies
  implementation 'com.android.support:appcompat-v7:27.1.1'

  // Our dependencies from ExpoView
  // DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
  implementation('com.facebook.android:audience-network-sdk:4.99.0') {
    exclude module: 'play-services-ads'
  }
  compileOnly 'org.glassfish:javax.annotation:3.1.1'
  implementation 'com.jakewharton:butterknife:8.4.0'
  implementation 'de.greenrobot:eventbus:2.4.0'
  implementation 'com.amplitude:android-sdk:2.9.2' // Be careful when upgrading! Upgrading might break experience scoping. Check with Jesse. See Analytics.resetAmplitudeDatabaseHelper
  implementation 'com.squareup.picasso:picasso:2.5.2'
  implementation 'com.google.android.gms:play-services-gcm:15.0.1'
  implementation 'com.google.android.gms:play-services-analytics:16.0.1'
  implementation 'com.google.android.gms:play-services-maps:15.0.1'
  implementation 'com.google.android.gms:play-services-auth:15.0.1'
  implementation 'com.google.android.gms:play-services-location:15.0.1'
  implementation 'com.google.android.gms:play-services-ads:15.0.1'
  annotationProcessor 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
  implementation "com.raizlabs.android:DBFlow-Core:2.2.1"
  implementation "com.raizlabs.android:DBFlow:2.2.1"
  implementation "com.madgag.spongycastle:core:1.53.0.0"
  implementation "com.madgag.spongycastle:prov:1.53.0.0"
  debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  // debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
  releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  implementation 'com.facebook.device.yearclass:yearclass:1.0.1'
  implementation 'commons-io:commons-io:1.3.2'
  implementation 'me.leolin:ShortcutBadger:1.1.4@aar'
  implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
  implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.7'
  implementation 'com.yqritc:android-scalablevideoview:1.0.1'
  implementation 'commons-codec:commons-codec:1.10'
  implementation 'com.segment.analytics.android:analytics:4.3.0'
  implementation 'com.google.zxing:core:3.2.1'
  implementation 'net.openid:appauth:0.4.1'
  implementation('com.airbnb.android:lottie:2.5.5')  {
      exclude group: 'com.android.support', module: 'appcompat-v7'
  }
  implementation 'io.branch.sdk.android:library:2.17.1'
  implementation('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  implementation 'com.android.support:exifinterface:27.1.1'
  implementation 'com.squareup.okhttp3:okhttp:3.11.0'
  implementation 'com.squareup.okio:okio:1.9.0'

  // Testing
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  // We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support:support-annotations:27.1.1'
  androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.0'
  androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
  androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'

  testImplementation 'junit:junit:4.12'
  testImplementation 'org.mockito:mockito-core:1.10.19'
  testImplementation 'org.robolectric:robolectric:3.8'
  testImplementation 'com.android.support.test:runner:1.0.2-alpha1'
  testImplementation 'com.android.support.test:rules:1.0.2-alpha1'

  implementation('host.exp.exponent:expoview:30.0.0@aar') {
    transitive = true
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp-urlconnection'
  }

  /* REMOVED_WHEN_DISTRIBUTING_FROM_HERE
  implementation(project(path: ':expoview')) {
    // Excluding okhttp3 included by expo-file-system
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp-urlconnection'
  }
  REMOVED_WHEN_DISTRIBUTING_TO_HERE */
}

// This has to be down here for some reason
apply plugin: 'com.google.gms.google-services'
cheolhow commented 6 years ago

@cobarx It looks like the current version of okhttp3 in react-native-video is 3.9.1. And this version does not include JavaNetCookieJar.

image

cobarx commented 6 years ago

@cheolhow The version in master uses 3.11.0. I still need to review and merge a few more PRs before I can release rnv 4.0.

cheolhow commented 6 years ago

@cobarx I am currently using 3.2.1, the latest version of react-native-radio. Is the latest version not working before 4.0?

cobarx commented 6 years ago

Cookie support was merged in 2.2.0 and hasn't changed in any meaningful way since then, so OkHTTP 3.9.1 should be fine.

It appears you may need to do some special configuration when dealing with an ejected Expo project: https://github.com/wkh237/react-native-fetch-blob/issues/549 I'm guessing that Expo is overriding the version of OkHTTP that you've specified in your gradle file. I would exclude okhttp at all times and see if that fixes it.

miversen commented 6 years ago

Having the same issue, any news?

gsunsnackv commented 5 years ago

Me too comment

I've spend couple days trying to find a solution. I tried to change the import of okhttp3. to expolib_v1.okhttp3. but got this error when build

node_modules/react-native-video/android-exoplayer/src/main/java/com/brentvatne/exoplayer/DataSourceUtil.java:80: error: no suitable constructor found for OkHttpDataSourceFactory(OkHttpClient,String,DefaultBandwidthMeter)
        OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, getUserAgent(context), bandwidthMeter);
                                                          ^
    constructor OkHttpDataSourceFactory.OkHttpDataSourceFactory(Factory,String,CacheControl) is not applicable
      (argument mismatch; OkHttpClient cannot be converted to Factory)
    constructor OkHttpDataSourceFactory.OkHttpDataSourceFactory(Factory,String,TransferListener) is not applicable
      (argument mismatch; OkHttpClient cannot be converted to Factory)
gsunsnackv commented 5 years ago

@cobarx (or anyone else), would it be easy for you to re-write (on a separate branch) the DataSourceUtil.java using the expolib_v1.okhttp3.* instead of the real okhttp3 ?

huynqhttt commented 5 years ago

Having the same issue. How to resolve this issue?

ryekerjh commented 5 years ago

This is still a problem

AnderAmorim commented 5 years ago

@gsunsnackv same problem here, any solution?

gsunsnackv commented 5 years ago

@AnderAmorim No solution. Restarted the project using pure react native, used alternative for every Expo package we used before

fpauer commented 5 years ago

For a production app, Expo is not worth IMHO.