2017-05-09 250 views
3

我想用我的React Native Android应用程序包含一个AAR文件,以便我可以使用本机代码访问其功能。我如何打包AAR,以便本地代码可以使用React Native Android导入它?谢谢!如何在React Native Android构建中包含AAR?

我得到的错误编译时是这样的:

~\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

创建反应原生本机模块(我已经做了几次之前,它工作正常,直到我尝试使用SDK)。

​​

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

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

+0

嘿,你能解决这个问题吗? – Micer

+0

嗨@Micer看到我刚刚发布的答案。 –

回答

1

有两个我想通过包括AAR来编译。

的Estimote SDK具体办法是此行添加到​​:

dependencies { 
    ... 
    compile 'com.estimote:sdk:1.0.3:[email protected]' 
} 

注意,文件已经过时,我的SDK的发布版本,所以搞清楚这是棘手的是什么类和方法使用。

另一种方式我奥尔斯包含在构建了以下变化:

创建文件夹android/libs,把AAR文件里面它。

在​​:

fileTree(dir: 'libs', include: '**/*.aar') 
    .each { File file -> 
     dependencies.add("compile", [ 
      name: file.name.lastIndexOf('.').with { it != -1 ? file.name[0..<it] : file.name }, 
      ext: 'aar' 
     ]) 
    } 

做完这些后,我可以开始导入的类和方法。

1

我尝试过很多办法,与Android STUDIO

打开文件夹,只是添加AAR或JAR

最简单的方法是打开生成的文件夹中去反应了Android原生的工作室项目。他们将aar添加到常规项目中。

enter image description here

enter image description here

在Android Studio中添加一如既往(友好余)

1)打开模块设置(右键单击该项目的顶部)

2)进口AAR/jar

3)添加依赖

+0

在工作室2.2.3为我工作 – dc10

相关问题