Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.so files in a react-native project (Android) #30297

Closed
Omarbenjelloun915 opened this issue Nov 1, 2020 · 5 comments
Closed

.so files in a react-native project (Android) #30297

Omarbenjelloun915 opened this issue Nov 1, 2020 · 5 comments
Labels

Comments

@Omarbenjelloun915
Copy link

Description

I am currently working on a mobile application with react-native which I would like to integrate my own SDK by calling it in the gradle.
implementation 'eu.polestar:naosdk:4.+'
So, I switched to the native code and I implemented the necessary functions, but the problem is that the SDK contains libc++_shared.so libraries which break the execution of the code and I have this

  • What went wrong:
    Execution failed for task ':app:mergeDebugNativeLibs'.
    A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
    More than one file was found with OS independent path 'lib/x86/libc++_shared.so'

By the way, I'm not interested in excluding the libc++_shared files, so I put them in a 'lib' folder by following the tree below:
image

And I add in the gradle: sourceSets { main.jniLibs.srcDirs += "src/main/lib" } to copy the .so files and take them into account in the execution.

At this stage, I avoided the previous error, the application is running normally but as soon as I try to use a feature from my SDK I encounter an unexpected error which returns to the fact the .so files are not taken taken into account in the project.

onSynchronizationFailure: Unexpected error

React Native version:

react: 16.13.1 => 16.13.1
react-native: ~0.63.3 => 0.63.3

Steps To Reproduce

The details of the SDK implementation are here: https://docs.nao-cloud.com/docs/mobile-sdk/android-sdk/quick-start/
and i just ran in terminal: react-native run-android

Expected Results

What I'm trying to do or find out is if there is a compromise between react-native's c ++ _ shared.so libraries and those provided by the SDK.

Snack, code example, screenshot, or link to a repository:

Here is my gradle:

`apply plugin: "com.android.application"
import com.android.build.OutputFile

project.ext.react = [
       enableHermes: false
]

apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/expo-updates/scripts/create-manifest-android.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
}

defaultConfig {
    applicationId 'com.polestar.naoreact'
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0.0"
}

sourceSets {
    main.jniLibs.srcDirs += "src/main/lib"
}

splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
}

buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        // Caution! In production, you need to generate your own keystore file.
        // see https://reactnative.dev/docs/signed-apk-android.
        signingConfig signingConfigs.debug
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // https://developer.android.com/studio/build/configure-apk-splits.html
        def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.google.android.gms:play-services-location:11.4.0'
implementation 'eu.polestar:naosdk:4.+' // final '+' ensures you are using the latest version in the 4.0 series

//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"  // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
    exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
}
addUnimodulesDependencies()

if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
    implementation jscFlavor
}

}

task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' }
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

@joaogithub
Copy link

Having the same issue. Any news about this?

@cortinico
Copy link
Contributor

You should be fine by removing the main.jniLibs.srcDirs += "src/main/lib" and adding a packaging option to your app module:

packagingOptions {
        pickFirst '**/libc++_shared.so'
}

@Omarbenjelloun915
Copy link
Author

@cortinico The SDK provides shared library(.so file), and I have no interest in excluding these files by putting in the gradle "pickfirst or exclude ..." because otherwise the application encounters bugs and in fact it cannot use the SDK.

@cortinico
Copy link
Contributor

and I have no interest in excluding these files by putting in the gradle "pickfirst or exclude ..."

The pickFirst will not exclude that file. Will tell AGP to pick the first occurrence of the .so library found. If both your library and RN are providing this native dependency, you have to specify which of the two .so should be picked, or remove it from your library so the one from RN will be used.

@cortinico
Copy link
Contributor

Closing as this has been fully addressed in React Native 0.71+
Please update to that version and report back if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants