为什么我的Fabric Native组件在运行`react-native run-android`时找不到React Native应用中的.aar文件依赖项?

mbyulnm0  于 2023-05-27  发布在  Android
关注(0)|答案(1)|浏览(125)

我正在为Android开发Fabric Native组件,作为React Native应用程序的一部分,需要包含.aar文件作为依赖项。
我已经在名为libs的目录中包含了一个静态lib文件mylibrary-debug.aar,该目录与Fabric Native组件的android文件夹中的src文件夹是同级文件。在运行react-native run-android时找不到该库,并且此Fabric组件包含在我的node_modules中。
build.gradle如下所示。

buildscript {
  ext.safeExtGet = {prop, fallback ->
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
  }
  repositories {
    google()
    gradlePluginPortal()
  }
  dependencies {
    classpath("com.android.tools.build:gradle:7.3.1")
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")
  }
}

def isNewArchitectureEnabled() {
  return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

apply plugin: 'com.android.library'
if (isNewArchitectureEnabled()) {
  apply plugin: 'com.facebook.react'
}
apply plugin: 'org.jetbrains.kotlin.android'

android {
  compileSdkVersion safeExtGet('compileSdkVersion', 33)
  namespace "com.composabletext"

  defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 21)
    targetSdkVersion safeExtGet('targetSdkVersion', 33)
    buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
  }
}

repositories {
  mavenCentral()
  google()
  flatDir{
    dirs 'libs'
  }
}

dependencies {
  implementation(name:'mylibrary-debug', ext:'aar')
  implementation 'com.facebook.react:react-native'
}

这个build.gradle配置允许我从Android Studio中的com.mylibrary.*导入Kotlin类,并且gradle同步成功,但是当我运行react-native run android并使用React Native Android应用的node_modules文件夹中的Fabric Native组件的源代码构建gradle项目时,构建失败,并出现以下情况:

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 -PreactNativeDebugArchitectures=arm64-v8a -PreactNativeArchitectures=arm64-v8a

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':composable-text:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':composable-text:debugCompileClasspath'.
   > Could not find :mylibrary-debug:.
     Required by:
         project :composable-text

为什么它在Android Studio中似乎可以工作,但在构建Android应用程序时却失败了?

qyswt5oh

qyswt5oh1#

我能够通过将以下内容添加到Android应用的build.gradle(Android应用项目根目录中的build.gradle)来解决这个问题
dirs project(':composable-text').file('libs')

相关问题