Android's Learning Path one

Source: Internet
Author: User

On the road of Android go farther = =, in the spirit of a childlike innocence to learn, did not expect to eventually become their own career. It's not that interest that makes Bill Gates and Steve Jobs their success, but that they really do make the world's richest man even if they buy a pie. However, if they are not interested, they will not seek this path, now they lack of interest and passion, but the accumulation of code to the program, that is, the gap between the strength, hope that through 1.1 points of progress to shorten the gap in strength. Programmers need to constantly think and accumulate, only to write here about their daily learning to have a process of understanding.

What we have to say before learning is the Android development environment, where we need not only Java more flexible and convenient interface development technology, but also need C and C + + efficient and concise. (actually I prefer C,java really greatly facilitates the development, however write more feel lazy to write C, because Java is almost packaged, and C in the research algorithm and the bottom of the Java more clear and efficient). Maybe it's just a love of C, maybe a consideration of efficiency, and here we want to take the C and C + + interfaces to make a complementary contribution to Java. This can be achieved using the Java JNI.

OK, Next we'll take the jdk,sdk,ndk,eclipse development environment.

1. JDK Build

The environment of Java Develope Kit is the foundation of all Java related development, here we choose 1.7 version (official website has 1.8 version can download by itself).

Configuration of the system environment (refer to http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html)

There are many examples of this online, which is to modify the environment variables in the system properties.

1.1 New environment variable java_home, variable value fill in the JDK installation directory (I am D:\Java\jdk1.7.0)

1.2 Edit the value of the PATH environment variable to increase the%java_home%\bin;%java_home%\jre\bin;

1.3 Edit the value of the CLASSPATH environment variable, increase.; %java_home%\lib;%java_home%\lib\tools.jar;

1.4 Environment-powered test, enter java-version and javac-version under CMD to see if the output is correct. If correct, the JDK environment is successfully installed.

2. Building the SDK

First, the SDK can go to the official web download, in view of the promising of the Celestial kingdom, you can choose FQ can also be downloaded with some mirror site, here is recommended a website (http://wear.techbrood.com/) Inside there are a lot of Android resources also include the following description of the ADT download.

Since it is often necessary to enter some commonly used commands on the command line in development, such as many of the ADB commands, it is also necessary to write the directories of these commands into path to facilitate the debugging of the program.

2.1 New environment variable sdk_home, fill in the directory of the SDK

2.2 Edit the value of the PATH environment variable to increase the%sdk_home%\platform;%sdk_home%\platform-tools;

2.4 Environment-powered test, enter ADB under CMD to see if the output is correct. If correct, the JDK environment is successfully installed.

3. The NDK Build

Similar to the above jdk and SDK = =, understanding is good ~ ~ ~

4. Eclipse's environmental build-up

This is the end of all environments, and if the JDK and the SDK and the ndk are OK, go to this step and complete all the tool paths into eclipse.

5. The Jni check is the focus of this session

5.1 Android Project New

Start with a new Android project

5.2 Then on Android project right click on Android Tools->add Native support and give the. so file a name. At this time the project will be more than one Jni folder, JNI under the Android.mk and XXX.cpp files. Android.mk is the makefile,xxx.cpp of the NDK project, which is the source file of the NDK.

The naming specification for JNI interfaces is:Java + calls the method's package name Class name + method name, for instance methods, there are two parameters that are necessary, a JNI environment pointer jnienv *, and another is a Java instance that invokes the method Jobject

#include <jni.h><string.h>extern"C"_ Jstring*  java_com_cgf_helloworldndk_mainactivity_jnitest (jnienv* env,jobject thiz) {      Return (env)->newstringutf ("Hello from jni by  ndktest! " );}

5.3 Loading XXX Library

The NDK library must be loaded with System.loadlaibrary in the static code block. So Library

 Public classMainactivityextendsActivity {Static{system.loadlibrary ("My-ndk"); }         //declares the native method of the JNI layer, using the native keyword     Public nativeString Stringfromjni (); Private TextView TextView = null;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
TextView TextView = (TextView) Findviewbyid (R.id.textview);
Textview.settext (Jnitest ());
}
}

5.4 Encounters unable to launch Cygpath. is Cygwin on the path? Error, the solution is as follows:

5.4.1 Project Right-click the properties->c/c++ build building settings to remove the Use default Build command and enter ${ndkroot}/ndk-build.cmd

5.4.2 Click on Environment in C + + build, point to add ... Add environment variable Ndkroot, the value of the NDK root directory

Try it, and you'll see in the view that the C code you've written has been successfully called.

Finally completed, although simple, but step by step down, do not make mistakes is also very important, to build their own development environment Bar ~ ~ ~ (The trapped programmer, said to be under the development of Linux, or a little panic, refueling and sleep)

Android's Learning Path one

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.