Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Add SoLoader indirection to Spectrum's FbJni
Browse files Browse the repository at this point in the history
Summary:
@public

This is in addition to the previous changes in commit 233ed53 .

It also make the FbJni module use the new indirection for the SoLoader allowing to use the platform's SoLoader.

Reviewed By: erikandre

Differential Revision: D15414876

fbshipit-source-id: 8ca1efe6686ed160bfcadde2cc8294bfc3aec662
  • Loading branch information
Daniel Hugenroth authored and facebook-github-bot committed May 21, 2019
1 parent 4d9ed16 commit 1fbd80e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
SpectrumSoLoader.init(this)

// try this variant if the Facebook SoLoader creates troubles for your release distribution
// SpectrumSoLoader.init(this, SpectrumSoLoader.SystemSoLoaderImpl())
}
}
17 changes: 17 additions & 0 deletions android/src/main/java/com/facebook/spectrum/SpectrumSoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.app.Application;
import android.content.Context;
import android.util.Log;
import com.facebook.jni.FbJniSoLoader;
import com.facebook.soloader.SoLoader;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -54,6 +55,9 @@ public static void init(final Context context, final SoLoaderWrapper soLoaderDel

sSoLoaderDelegate = soLoaderDelegate;
sSoLoaderDelegate.init(context);

// also make our FbJni copy use this SoLoader abstraction
FbJniSoLoader.delegate = new SpectrumImplForFbJniSoLoaderDelegate();
}

public static void loadLibrary(final String shortName) {
Expand Down Expand Up @@ -105,4 +109,17 @@ public void loadLibrary(final String shortName) {
System.loadLibrary(shortName);
}
}

/**
* Delegate implementation for the {@link FbJniSoLoader} to use this {@link SpectrumSoLoader}.
* Required to avoid circular dependencies between modules.
*/
private static final class SpectrumImplForFbJniSoLoaderDelegate
implements FbJniSoLoader.SoLoaderWrapper {

@Override
public void loadLibrary(final String shortName) {
SpectrumSoLoader.loadLibrary(shortName);
}
}
}
1 change: 0 additions & 1 deletion androidLibs/fbjni/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ android {

dependencies {
compileOnly deps.jsr305
implementation deps.soloader
}

apply from: rootProject.file('gradle/release.gradle')
Expand Down
17 changes: 17 additions & 0 deletions androidLibs/fbjni/java/com/facebook/jni/FbJniSoLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.facebook.jni;

/** SoLoader delegate to allow making FbJni use the SpectrumSoLoader */
public final class FbJniSoLoader {

public static SoLoaderWrapper delegate = null;

private FbJniSoLoader() {}

public static void loadLibrary(final String shortName) {
delegate.loadLibrary(shortName);
}

public interface SoLoaderWrapper {
void loadLibrary(final String shortName);
}
}
3 changes: 1 addition & 2 deletions androidLibs/fbjni/java/com/facebook/jni/HybridData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.facebook.jni;

import com.facebook.jni.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;

/**
* This object holds a native C++ member for hybrid Java/C++ objects.
Expand All @@ -22,7 +21,7 @@
public class HybridData {

static {
SoLoader.loadLibrary("spectrumfbjni");
FbJniSoLoader.loadLibrary("spectrumfbjni");
}

@DoNotStrip private Destructor mDestructor = new Destructor(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
package com.facebook.jni;

import com.facebook.jni.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;

@DoNotStrip
public class ThreadScopeSupport {
static {
SoLoader.loadLibrary("spectrumfbjni");
FbJniSoLoader.loadLibrary("spectrumfbjni");
}

// This is just used for ThreadScope::withClassLoader to have a java function
Expand Down

0 comments on commit 1fbd80e

Please sign in to comment.