Android Full Environment setup process

Source: Internet
Author: User

JDK Environment variables and settings

1. Download and install the JDK
2. My Computer-Advanced settings-environment variables
2.1 Java_home: Your JDK installation directory
2.2 Path:%java_home%\bin;%java_home%\jre\bin;
2.3 CLASSPATH:.; %java_home%\lib;%java_home%\lib\tools.jar
3. Start-run-cmd, run Java and Javac in the command window that starts, and make sure the output is correct

ANDROIDSDK environment variable Settings

1. Download the Android SDK package
2. My Computer-Advanced settings-environment variables
2.1 android_home:android SDK installation directory
2.2 added in path:%android_home%\platforms;%android_home%\platform-tools;%android_home%\tools;
3. Start-run-cmd, run adb,android in the command window that starts

Android NDK environment variable settings

1. Download the Android NDK R7 above package
2. My Computer-Advanced settings-environment variables
2.1 android_ndk:android NDK installation directory
2.2 added in path:%android_ndk%;%android_ndk%\build;
3. Start-run-cmd, run ndk-build in the command window that starts

Developing JNI programs with eclipse

Eclipse is best used by Google's official ADT build package, if you are configuring Eclipse to add the CDT plugin, Android ADT,NDK plugin
1. Create a new normal Android project.
2.window-preferce-android (NDK) Setting the NDK path

4. Select items, right-click, select Android Tools-add Native Supprot, fill in the pop-up input box .so name. General use lib+ 3. Select the item, Right-click-properties-c/c++ general-paths and Symbols->add-file System tree->c:\develop\android-ndk-r9d\platforms\ Android-19\arch-arm\usr\include
4. Under the JNI generated by Eclipse, .cpp to 5. Add a native method to the activity to return a string

@Override protected void onCreate Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_main);        Toast.maketext (This, SayHello (), Toast.length_long). Show ();    Private native SayHello ();

6. Enter the project's SRC directory by cmd and run the Javah package name. Activity name

Javah com.example.testjni.MainActivity

7. In the Eclipse Project, refresh the directory, locate the generated header file, and copy the method name to a file that has been modified to *.c under JNI.
8. Set the formal parameter name in the newly added method of the C file
Javah Generated method name

jniexport jstring jnicall java_com_example_testjni_mainactivity_sayhello  (jnienv *, jobject);

modified method in C file

Jniexport jstring jnicall Java_com_example_testjni_mainactivity_sayhello  return(*env)- >Newstringutf (env,"Hello");}

9. In the upper left corner, make sure that you are currently in C + + view, find a button like a hammer, click, observe the output on the console and find similar

[Armeabi] Compile thumb  : Testjni <= libtestjni.c

10. In activity using the Jni method, add the following. Note that the name in the LoadLibrary and the compile thumb output in the console are always

Static {        System. LoadLibrary("Testjni");    }

11. Running the Android project, if you can successfully eject the TOST hint, it means that the JNI call succeeded.

Tips
The method name used in 1.JNI and the corresponding rule used in activity

Com.example.testjni.Activity.sayHello () = = Java_com_example_testjni. Activity_sayhello ()

Android Full Environment setup process

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.