有可能从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.