如何在React Native Android构建中包含AAR? [英] How to include AAR in React Native Android build?

查看:716
本文介绍了如何在React Native Android构建中包含AAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的React Native Android应用程序中包含一个AAR文件,以便我可以使用本机代码访问其功能.如何捆绑AAR,以便本机代码可以将其与React Native Android一起导入?谢谢!

I'm trying to include an AAR file with my React Native Android app so that I can access its features using native code. How can I bundle an AAR so that native code can import it with React Native Android? Thanks!

编译时出现的错误是

~\app\android\app\src\main\java\com\grind\GrindModule.java:13: error: package com.estimote.sdk does not exist
import com.estimote.sdk.EstimoteSDK;
                        ^

我进行了以下更改:

创建android/app/libs/estimote-sdk.aar.

创建react native本地模块(我已经做过几次,直到我尝试使用SDK为止,它都可以正常工作.

Create react native native module (I've done this a few times before, it works fine until I try to use the SDK).

android/app/build.gradle

dependencies {
    compile(name:'estimote-sdk', ext:'aar')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

android/build.gradle

...
allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        flatDir {
            dirs 'libs'
        }
    }
}

这些是包括SDK的说明: https://github.com/Estimote/Android-SDK#installation

These are the instructions for including the SDK: https://github.com/Estimote/Android-SDK#installation

https://github.com/Estimote/Android-SDK/blob/master/Docs/manual_installation.md#estimote-sdk-for-android-manual-installation

推荐答案

library.aar文件复制到react-native-module-name/android/libs中.如果libs文件夹不存在,请创建它.

Copy the library.aar file into react-native-module-name/android/libs. Create the libs folder if it doesn't exists.

react-native-module-name/android/build.gradle中:

dependencies {
  implementation fileTree(dir: "libs", include: ["*.aar"])
  implementation 'com.facebook.react:react-native:+'  // From node_modules
}

这篇关于如何在React Native Android构建中包含AAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆