2017-05-09 87 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

相關問題