fix: 🐛 Korrekt registrering av CookieJar för Android
This commit is contained in:
parent
c43e34cec5
commit
74de762f9a
|
@ -191,7 +191,7 @@ dependencies {
|
||||||
//noinspection GradleDynamicVersion
|
//noinspection GradleDynamicVersion
|
||||||
implementation "com.facebook.react:react-native:+" // From node_modules
|
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}") {
|
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
|
||||||
exclude group:'com.facebook.fbjni'
|
exclude group:'com.facebook.fbjni'
|
||||||
|
|
|
@ -2,22 +2,32 @@ package org.skolplattformen.app;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.facebook.react.PackageList;
|
import com.facebook.react.PackageList;
|
||||||
import com.facebook.react.ReactApplication;
|
import com.facebook.react.ReactApplication;
|
||||||
import com.facebook.react.ReactInstanceManager;
|
import com.facebook.react.ReactInstanceManager;
|
||||||
import com.facebook.react.ReactNativeHost;
|
import com.facebook.react.ReactNativeHost;
|
||||||
import com.facebook.react.ReactPackage;
|
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.OkHttpClientFactory;
|
||||||
import com.facebook.react.modules.network.OkHttpClientProvider;
|
import com.facebook.react.modules.network.OkHttpClientProvider;
|
||||||
import com.facebook.react.modules.network.ReactCookieJarContainer;
|
import com.facebook.react.modules.network.ReactCookieJarContainer;
|
||||||
import com.facebook.soloader.SoLoader;
|
import com.facebook.soloader.SoLoader;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.CookieHandler;
|
import java.net.CookieHandler;
|
||||||
|
import java.net.CookieManager;
|
||||||
|
import java.net.CookiePolicy;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class MainApplication extends Application implements ReactApplication {
|
public class MainApplication extends Application implements ReactApplication {
|
||||||
private final ReactNativeHost mReactNativeHost =
|
private final ReactNativeHost mReactNativeHost =
|
||||||
|
@ -53,20 +63,16 @@ public class MainApplication extends Application implements ReactApplication {
|
||||||
SoLoader.init(this, /* native exopackage */ false);
|
SoLoader.init(this, /* native exopackage */ false);
|
||||||
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
||||||
|
|
||||||
ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
|
ReactCookieJarContainer reactCookieJarContainer = new ReactCookieJarContainer();
|
||||||
mReactInstanceManager.addReactInstanceEventListener(reactContext -> {
|
CookieManager cookieManager = new CookieManager();
|
||||||
OkHttpClientProvider.setOkHttpClientFactory(new OkHttpClientFactory() {
|
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
|
||||||
@Override
|
reactCookieJarContainer.setCookieJar(new SkolplattformenCookieJar(cookieManager));
|
||||||
public OkHttpClient createNewNetworkModuleClient() {
|
NetworkingModule.setCustomClientBuilder(new NetworkingModule.CustomClientBuilder() {
|
||||||
ReactCookieJarContainer reactCookieJarContainer = new ReactCookieJarContainer();
|
@Override
|
||||||
reactCookieJarContainer.setCookieJar(new SkolplattformenCookieJar(CookieHandler.getDefault()));
|
public void apply(OkHttpClient.Builder builder) {
|
||||||
return OkHttpClientProvider.createClientBuilder(reactContext)
|
builder.cookieJar(reactCookieJarContainer);
|
||||||
.cookieJar(reactCookieJarContainer)
|
}
|
||||||
.build();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
package org.skolplattformen.app;
|
package org.skolplattformen.app;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,6 +33,9 @@ public final class SkolplattformenCookieJar implements CookieJar {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveFromResponse(@NonNull HttpUrl url, @NonNull List<Cookie> cookies) {
|
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) {
|
if (cookieHandler != null) {
|
||||||
List<String> cookieStrings = new ArrayList<>();
|
List<String> cookieStrings = new ArrayList<>();
|
||||||
for (Cookie cookie : cookies) {
|
for (Cookie cookie : cookies) {
|
||||||
|
@ -48,6 +53,11 @@ public final class SkolplattformenCookieJar implements CookieJar {
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<Cookie> loadForRequest(@NonNull HttpUrl url) {
|
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!
|
// 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>> headers = Collections.emptyMap();
|
||||||
Map<String, List<String>> cookieHeaders;
|
Map<String, List<String>> cookieHeaders;
|
||||||
|
|
|
@ -13,7 +13,7 @@ buildscript {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,17 @@
|
||||||
# Project-wide Gradle settings.
|
## For more details on how to configure your build environment visit
|
||||||
|
|
||||||
# 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
|
|
||||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||||
|
#
|
||||||
# Specifies the JVM arguments used for the daemon process.
|
# Specifies the JVM arguments used for the daemon process.
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
# 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
|
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||||
|
#
|
||||||
# When configured, Gradle will run in incubating parallel mode.
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
# 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
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
|
#Thu Apr 01 10:00:57 CEST 2021
|
||||||
# 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
|
|
||||||
FLIPPER_VERSION=0.75.1
|
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