fix: 🐛 Korrekt registrering av CookieJar för Android
This commit is contained in:
parent
c43e34cec5
commit
74de762f9a
|
@ -191,7 +191,7 @@ dependencies {
|
|||
//noinspection GradleDynamicVersion
|
||||
implementation "com.facebook.react:react-native:+" // From node_modules
|
||||
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||
|
||||
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
|
||||
exclude group:'com.facebook.fbjni'
|
||||
|
|
|
@ -2,22 +2,32 @@ package org.skolplattformen.app;
|
|||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.facebook.react.PackageList;
|
||||
import com.facebook.react.ReactApplication;
|
||||
import com.facebook.react.ReactInstanceManager;
|
||||
import com.facebook.react.ReactNativeHost;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.modules.network.ForwardingCookieHandler;
|
||||
import com.facebook.react.modules.network.NetworkingModule;
|
||||
import com.facebook.react.modules.network.OkHttpClientFactory;
|
||||
import com.facebook.react.modules.network.OkHttpClientProvider;
|
||||
import com.facebook.react.modules.network.ReactCookieJarContainer;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
import java.net.CookiePolicy;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
private final ReactNativeHost mReactNativeHost =
|
||||
|
@ -53,20 +63,16 @@ public class MainApplication extends Application implements ReactApplication {
|
|||
SoLoader.init(this, /* native exopackage */ false);
|
||||
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
||||
|
||||
ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
|
||||
mReactInstanceManager.addReactInstanceEventListener(reactContext -> {
|
||||
OkHttpClientProvider.setOkHttpClientFactory(new OkHttpClientFactory() {
|
||||
@Override
|
||||
public OkHttpClient createNewNetworkModuleClient() {
|
||||
ReactCookieJarContainer reactCookieJarContainer = new ReactCookieJarContainer();
|
||||
reactCookieJarContainer.setCookieJar(new SkolplattformenCookieJar(CookieHandler.getDefault()));
|
||||
return OkHttpClientProvider.createClientBuilder(reactContext)
|
||||
.cookieJar(reactCookieJarContainer)
|
||||
.build();
|
||||
}
|
||||
});
|
||||
ReactCookieJarContainer reactCookieJarContainer = new ReactCookieJarContainer();
|
||||
CookieManager cookieManager = new CookieManager();
|
||||
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
|
||||
reactCookieJarContainer.setCookieJar(new SkolplattformenCookieJar(cookieManager));
|
||||
NetworkingModule.setCustomClientBuilder(new NetworkingModule.CustomClientBuilder() {
|
||||
@Override
|
||||
public void apply(OkHttpClient.Builder builder) {
|
||||
builder.cookieJar(reactCookieJarContainer);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
package org.skolplattformen.app;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -31,6 +33,9 @@ public final class SkolplattformenCookieJar implements CookieJar {
|
|||
|
||||
@Override
|
||||
public void saveFromResponse(@NonNull HttpUrl url, @NonNull List<Cookie> cookies) {
|
||||
for (Cookie cookie : cookies) {
|
||||
Log.d("CookieJar", "saveFromResponse: " + cookie.name() + ": " + cookie.value());
|
||||
}
|
||||
if (cookieHandler != null) {
|
||||
List<String> cookieStrings = new ArrayList<>();
|
||||
for (Cookie cookie : cookies) {
|
||||
|
@ -48,6 +53,11 @@ public final class SkolplattformenCookieJar implements CookieJar {
|
|||
@Override
|
||||
@NonNull
|
||||
public List<Cookie> loadForRequest(@NonNull HttpUrl url) {
|
||||
if (cookieHandler == null) {
|
||||
Platform.get().log(WARN, "No cookie handler set!", null);
|
||||
Log.w("CooieJar", "No cookie jag set!");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// The RI passes all headers. We don't have 'em, so we don't pass 'em!
|
||||
Map<String, List<String>> headers = Collections.emptyMap();
|
||||
Map<String, List<String>> cookieHeaders;
|
||||
|
|
|
@ -13,7 +13,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:4.1.0")
|
||||
classpath("com.android.tools.build:gradle:4.1.3")
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
|
|
|
@ -1,28 +1,17 @@
|
|||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
## For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
#
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
||||
# Default value: -Xmx1024m -XX:MaxPermSize=256m
|
||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
|
||||
#
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
|
||||
# Version of flipper SDK to use with React Native
|
||||
#Thu Apr 01 10:00:57 CEST 2021
|
||||
FLIPPER_VERSION=0.75.1
|
||||
android.enableJetifier=true
|
||||
android.useAndroidX=true
|
||||
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"
|
||||
|
|
Loading…
Reference in New Issue