使用最新版AndroidStudio2.0進行NDK開發並且鏈接第三方so庫

配置:
1.gradle-wrapper.properties中配置distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
2.項目gradle中buildscript下配置
dependencies {
classpath “com.android.tools.build:gradle-experimental:0.7.0-alpha1”
}
修改gradle文件
1.moudle的gradle文件中用apply plugin: ‘com.android.model.application’代替以前的 apply plugin:”com.android.application”
2.gradle結構也和過去不太一樣了 android 外面要加一層model,用官方的話說就是Configuration is wrapped with the model { } block
3.如果不鏈接第三方靜態庫的話只需要配置android.ndk 和 android.productFlavors就可以了
4.如果需要鏈接第三方靜態庫需要如下配置 , yourlib需要替換成你所引用的庫的name

repositories {
            libs(PrebuiltLibraries) {
                yourlib{
                    headers.srcDir "src/main/jni/lib/include(第三方庫頭文件存放位置)"
                    binaries.withType(SharedLibraryBinary) {
                        sharedLibraryFile = file("src/main/jni/lib/libyourlib.so(第三方庫so位置)")
                    }
                }
            }
    }
    android.sources {
        main{
            jni {
                dependencies {
                    library "yourlib" linkage "shared"
                }
            }
            jniLibs {
                dependencies {
                    library "yourlib"
                }
            }
        }
    }

ok build successful

參考
http://ph0b.com/new-android-studio-ndk-support/#more-236
http://tools.android.com/tech-docs/new-build-system/gradle-experimental

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章