android studio添加so庫的方法

來源:互聯網
上載者:User

標籤:

根據Gradle的版本不同,匯入有以下兩種方法

方法一

將so檔案拷貝到libs檔案夾下,然後 在moudle的gradle 配置添加以下代碼:  

task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {
destinationDir file("$projectDir/libs")
baseName "Native_Libs2"
extension "jar"
from fileTree(dir: "libs", include: "**/*.so")
into "lib"
}

tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}

 

完整的gradle檔案如下:

  1. apply plugin: ‘com.android.application‘  
  2.   
  3. android {  
  4.     compileSdkVersion 21  
  5.     buildToolsVersion "21.1.0"  
  6.   
  7.     defaultConfig {  
  8.         applicationId "com.wujay.footerballstar"  
  9.         minSdkVersion 8  
  10.         targetSdkVersion 21  
  11.         versionCode 1  
  12.         versionName "1.0"  
  13.     }  
  14.   
  15.     buildTypes {  
  16.         release {  
  17.             runProguard false  
  18.             proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘  
  19.         }  
  20.     }  
  21.   
  22.     task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {  
  23.         destinationDir file("$projectDir/libs")  
  24.         baseName "Native_Libs2"  
  25.         extension "jar"  
  26.         from fileTree(dir: "libs", include: "**/*.so")  
  27.         into "lib"  
  28.     }  
  29.   
  30.     tasks.withType(JavaCompile) {  
  31.         compileTask -> compileTask.dependsOn(nativeLibsToJar)  
  32.     }  
  33. }  
  34.   
  35. dependencies {  
  36.     compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])  
  37.     compile ‘com.android.support:appcompat-v7:21.0.0‘  
  38.     compile files(‘libs/jpush-sdk-release1.7.2.jar‘)  
  39.     compile files(‘libs/umeng_sdk.jar‘)  
  40.     compile files(‘libs/libammsdk.jar‘)  
  41. }  

 

方法二:

 

android studio添加so庫的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.