Androidstudio NDK Introduction Summary (1)

Source: Internet
Author: User

There are two ways to develop NDK in Android Studio:
1 use the already compiled. so dynamic library;
2 Development using C + + source code.

1.1 using pre-compiled. So dynamic libraries

Use the Ndk-build tool to compile the. So first and then refer to it in Android studio.
The path of the. So store:
"Module name" \src\main\jnilibs\armeabi

If you do not want to put. So on the default path above, you can configure the following in Buid.gradle:

android {
// .. android settings ..
sourceSets.main {
jniLibs.srcDir ‘‘ // <-- 你的.so库的实际路径
}
}
}

1.2 Compiling the C + + source code

1.2.1 Need to configure the path of the NDK;
Open the module settings and set the path to the NDK.

You can also set it directly in the local.properties in the file:
Ndk.dir=e:\jni\android-ndk-r10

1.2.2 Gradle Configuring the NDK module
Configuration in Build.gradle:

android {    defaultConfig {        ndk{            "two"            //生成的so名字            "log""z""m"  //添加依赖库文件,因为有log打印等            "armeabi""armeabi-v7a""x86"  //输出指定abi体系结构下的so库        }    }}

Of course, you can configure more options, as follows:
NDK {
ModuleName "Myepicgamecode"
Define some macros
CFlags "-dandroid_ndk-d_debug dnull=0"
Link with these libraries
Ldlibs "EGL", "GLESv3", "DL", "Log"
Use shared STLport Library
STL "Stlport_shared"}
}

1.2.3 Adding C + + source code
By default, you need to put the C + + source code under the [module]/src/main/jni/path.

1.2.4. Sub-platform configuration compilation (optional)
Configuration in Build.gradle:
Android {
// .. Android settings.
productflavors {
x86 {
NDK {
Abifilter "x86"
}
}
Arm {
NDK {
Abifilter "armeabi-v7a"
}
}
MIPS {
NDK {
Abifilter "MIPS"
}
}
}
}//Android

1.2.5 Error Rollup
Error 1:
Make.exe: * No rule to make target
solutions;
In a bug in Windows NDK, this problem occurs when only one file is compiled, and the workaround is to add an empty util.c file to the Jni folder
Reference: http://blog.csdn.net/sodino/article/details/41946607

Error 2:
Java.lang.UnsatisfiedLinkError:Couldn ' t load from loader Dalvik.system.PathClassLoader
solutions;
Under the Libs folder, create a new armeabi-v7a, and then copy the. So files under Armeabi in the past.
Reference: http://www.cnblogs.com/freexiaoyu/p/4046431.html
Other scenarios: http://blog.csdn.net/hj563308597/article/details/50395469 (No validation)

Source: Https://github.com/alifeidao/TestNdK

Androidstudio NDK Introduction Summary (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.