【问题标题】:Add pre-built .so files in project using Android Gradle plugin 0.7.3使用 Android Gradle 插件 0.7.3 在项目中添加预构建的 .so 文件
【发布时间】:2014-01-20 22:55:59
【问题描述】:

很久以后,Android Gradle 插件 0.7.3 中添加了在 Android 项目中添加预构建 .so 文件的支持。但与我不同的是,很多人仍在使用 hack/workaround 添​​加预构建的 .so 文件,即使用特定层次结构压缩文件,然后重命名为 .jar。以下是如何正确添加 .so 文件的分步指南。

【问题讨论】:

    标签: android android-ndk android-studio android-gradle-plugin


    【解决方案1】:

    那么如何添加预构建的 .so 文件?

    1) 将您的 android studio 升级到 0.4.0
    2) 将 gradle-wrapper.properties 中的 "distributionUrl=" 替换为 "distributionUrl=http://services.gradle.org/distributions/gradle-1.9-all.zip"
    3)添加/替换你的'buildscript'部分build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.7.3'
        }
    } 
    

    4)

    5) 在 build.gradle 中添加以下内容:

    android {
        compileSdkVersion 18
        buildToolsVersion "18.1.0"
    
        defaultConfig {
            minSdkVersion 10
            targetSdkVersion 18
        }
    
        productFlavors {
            x86 {
                ndk {
                    abiFilter "x86"
                }
            }
            arm {
                ndk {
                    abiFilters "armeabi-v7a", "armeabi"
                }
            }
    
        }
    
    
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/notice.txt'
        }
    }    
    

    6) 构建您的项目。

    【讨论】:

    • @CrossleSong 不好意思,没看懂,能详细点吗?
    • 预构建 NDK 库项目。我有一个 Android 库项目,有 prebuild so 文件。
    • @GilbertoIbarra 请分享您的脚本。
    【解决方案2】:

    我终于实现了这段代码..

    buildscript {
     repositories {
        mavenCentral()
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:0.7.3'
     }
    }
    apply plugin: 'android'
    
    repositories {
      mavenCentral()
    }
    
    android {
    
    compileSdkVersion 19
    buildToolsVersion "19.0.1"
    
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
    
    productFlavors {
        x86 {
            ndk {
                abiFilter "x86"
            }
        }
        arm {
            ndk {
                abiFilters "armeabi-v7a", "armeabi"
            }
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多