简体   繁体   中英

How create a library from react native app

It is possible create a library from react native to use in android project? The same question for create objective-c library, like a pod.

In case of Android, this is my gradle:

apply plugin: "com.android.library"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

import com.android.build.OutputFile

...


android {

  ...

  libraryVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
            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
            }
        }
    }
}

I change the plugin from com.android.application to com.android.library and change applicationVariants to libraryVariants .

But, when I try build the library, I got this error:

Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.LibraryExtension.  

您可以在React Native官方文档中使用此文档

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM