Android ORM Series Greendao custom type converter with code obfuscation configuration

Source: Internet
Author: User

Starting with Android Studio 1.3 Beta1, the NDK is supported. However, a new experimental gradle build tool is used. Official address Http://tools.android.com/tech-docs/new-build-system/gradle-experimental, English good can directly read the original text.

Please update Android studio to the latest version prior to configuration, the latest version is 1.4 BATA4

and download the NDK using the SDK Manager built into Android studio.

or right-click on Project Structure to open the SDK Location page to install

Note that this NDK is installed after its directory in the SDK directory under the Ndk-bundle directory, unlike in the past.

To modify the file see

First, you need to modify the Gradle in the root directory to an experimental gradle

‘com.android.tools.build:gradle-experimental:0.2.0‘

That's the end of it.

and requires Gradle 2.5 support to change the version in Gradle/gradle-wrapper.properties to 2.5

distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

That's the end of it.

Then modify the original app/ Build.gradle, note that now each configuration is an equal sign, and the use of com.android.model.application instead of the original com.android.application, if it is the library, it is Com.android.mo Del.library. Then the android is covered with a layer of model. The original buildtypes inside the android moved to the outside. Wait, look at the following, notice the change.

Apply plugin:' Com.android.model.application 'model{Android {compilesdkversion = ABuildtoolsversion ="23.0.1"Defaultconfig. with{ApplicationID ="Com.kltz88.car.jnidemo"Minsdkversion.apilevel = -Targetsdkversion.apilevel = AVersioncode =1Versionname ="1.0"} tasks.withtype (Javacompile) {//Specify compile JDK versionsourcecompatibility = javaversion.version_1_7 targetcompatibility = javaversion.version_1_7}} an DROID.NDK {modulename ="Test"Ldlibs + ="Log"Abifilters + ="Armeabi"Abifilters + ="armeabi-v7a"Abifilters + ="x86"} android.buildtypes {release {minifyenabled =falseProguardfiles + =file(' Proguard-rules.pro ')}}}dependencies {compile Filetree (dir:' Libs ',include: [' *.jar ']) Compile' com.android.support:appcompat-v7:22.2.1 '}

For the NDK configuration in Android.ndk, the module name is required. It then uses log, and supports armeabi,armeabi-v7a,x86 three platforms.

Then add the JNI directory and right-click on the new JNI directory on main

In the popup window you can modify the JNI directory by default in Main/jni

Create a new class for test, load the JNI library, declare the native method

publicclass Test {    static {        System.loadLibrary("test");    }    publicvoidtest();}

You'll find that the test method is red.

method to generate C layer by pressing alt+enter above

Modify to the code below

#include <jni.h>#include "android/log.h"void JNICALLJava_com_kltz88_car_jnidemo_Test_test(JNIEnv *env, jobject instance) {    __android_log_write(ANDROID_LOG_ERROR,"TAG","TEST");}

If you need to generate a header file, use the command line to

The corresponding header file is then generated in the JNI directory

The Java layer is then called

publicclass MainActivity extends AppCompatActivity {    @Override    protectedvoidonCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Test t=new Test();        t.test();    }}

You will see the output of the log.

Note If the corresponding version of Java is not specified in Gradle, the runtime may error

tasks.withType(JavaCompile) {            //指定编译JDK版本            sourceCompatibility = JavaVersion.VERSION_1_7            targetCompatibility = JavaVersion.VERSION_1_7        }

The error message is as follows, the error is encountered and the above code can be

Finally, debugging is the problem, in theory it should be supported debugging, but I did not experiment on Windows success. Post the steps below.

Add native Operation method

Revision changed to

Then the breakpoint, in theory, can be debugged, but I met the following problems, resulting in the inability to continue, also checked, check not the problem, so it, another day under the Linux test is not normal.

You will find the whole process down, the original android.mk and application.mk are no longer needed, all configurations are configured in Gradle.

The official GitHub sample code
Https://github.com/googlesamples/android-ndk

My sample Code
http://download.csdn.net/detail/sbsujjbcy/9108775

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android ORM Series Greendao custom type converter with code obfuscation configuration

Related Article

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.