找到你要的答案

Q:Android Studio adds libapp.so to the resulting apk, what is it and how to turn it off?

Q:Android Studio增加了libapp.so导致apk,怎样关掉它吗?

Android Studio 1.1 generated apk file (located @ app/build/outputs/apk folder) contains the lib directory, and for every cpu type there exists a non-empty folder, like /x86. Each of these folder contain a libapp.so shared library that is around 5Kb in size per cpu.

I've searched the net and the only thing I found so far is this link from Intel https://software.intel.com/en-us/articles/building-native-android-apps-using-intelr-c-compiler-in-android-studio that shows how to change the default libapp.so to user-provided library.

So, I guess that this library (libapp.so) is somehow built by gradle. Gradle of course is the king of hiding the things away.

In fact I do my own native library building, using ndk-build command line tool, and my libs are placed alongside that libapp.so. It's not causing any issues btw, but I feel that I'm losing the control over what is built and why.

Here's my humble build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

 /**
 * Path to *.so files
 */
    sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/libs']
            jni.srcDirs = [] //disable automatic ndk-build
        }
    }
    defaultConfig {
        applicationId "com.sample.android"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
}

How can I disable this libapp.so being built, or at least know what's going on with the gradle (build-hideomation tool) doing his own things behind the curtain?

Android Studio 1.1生成的apk文件(位于“应用程序/建设/输出/ APK文件夹)包含的lib目录中,并为每一个CPU类型存在一个非空的文件夹,如x86。这些文件夹包含一个libapp.so共享库,约5KB大小每CPU。

我在网上搜寻,只有一件事我发现到目前为止这个链接从英特尔https://software.intel.com/en-us/articles/building-native-android-apps-using-intelr-c-compiler-in-android-studio显示如何更改默认libapp.so用户提供图书馆。

所以,我想,这个图书馆(libapp。所以)在某种程度上是由摇篮。Gradle当然是隐藏的东西王。

事实上,我做我的故乡的图书馆建筑,使用ndk-build命令行的工具,我放在旁边,libapp.so LIBS。它不会造成任何问题,顺便说一句,但我觉得我是造了什么和为什么失去控制。

这是我的卑微的build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

 /**
 * Path to *.so files
 */
    sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/libs']
            jni.srcDirs = [] //disable automatic ndk-build
        }
    }
    defaultConfig {
        applicationId "com.sample.android"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
}

如何禁用这libapp.so正在修建的,或者至少知道怎么回事摇篮(建设hideomation工具)做自己事的幕后?

answer1: 回答1:

defaultConfig { ndk { moduleName "yourSelfLib" } }

defaultConfig { ndk { moduleName "yourSelfLib" } }

android  gradle  android-ndk