如何从React Native应用程序创建库

时间:2019-02-20 23:16:52

标签: android ios reactjs react-native

有可能从react native创建一个库以在android项目中使用吗?创建objective-c库(例如pod)的问题相同。

如果是Android,这是我的荣幸:

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
            }
        }
    }
}

我将插件从com.android.application更改为com.android.library,并将applicationVariants更改为libraryVariants

但是,当我尝试构建库时,出现此错误:

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

1 个答案:

答案 0 :(得分:0)

您可以使用this document来响应本机官方文档。