是否有可能创建一个来自React Native到Android Project使用的库?创建Objective-C库的问题,例如Pod。
在Android的情况下,这是我的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
}
}
}
}
我将插件从com.android.application
更改为com.android.library
,然后将applicationVariants
更改为libraryVariants
。
但是,当我尝试构建库时,我会收到此错误:
Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.LibraryExtension.
您可以在React Native官方文档中使用此文档。