Android Environment Build Ndk+adt (free Cywgin)

Source: Internet
Author: User


JDK Download:

1http://www.oracle.com/technetwork/java/javase/downloads/index.html2 Configuring environment variables

java_home: create. The value is: The JDK's installation path on your computer.

PATH: edit. The value is:%java_home%\bin.

CLASSPATH : Edit. Configure two values with a value of:.; %java_home%\lib\tools.jar(where the first value indicates that the JVM First searches the current directory).

3 Test Variables

Open cmd, enter command Java–version and Javac, and if return information is present, the setting is successful.

ADT Download:

Http://dl.google.com/android/adt/adt-bundle-windows-x86_64-20140702.zip

Eclipse + SDK +adt Integration Toolkit, or you can use Eclipse to build the first

Extract:

NDK Download

Http://dl.google.com/android/ndk/android-ndk-r10e-windows-x86_64.exe

Extract:

Configuring the SDK and NDK

sdk configuration: adt integrated eclipse tool is configured by default for sdk

NDK Configuration : Open Eclipse , point WINDOW->PREFERENCES->ANDROID->NDK , set NDK Path


possible issues: The ndk option is not found

solution: Download NDK component Com.android.ide.eclipse.ndk_23.0.2.1259578.jar. Copy the file "Com.android.ide.eclipse.ndk_23.0.2.1259578.jar" to the Eclipse/plugins directory that comes with the SDK.

: software Baidu Cloud Link: Http://pan.baidu.com/s/1qWz5rNA Password: 0QHK

Build your first Android project:

1. Create a new Android application project with no changes to the default values for all parameters


2.Right-click on the projectAndroidtools->add Native Support, the name is the default value and no change is required. After confirmation, the project is automatically generatedJNIthe folder,JNIunder aandroid.mkand theMy-ndk.cppfile. android.mkis aNDKWorks ofMakefile,NDKTest.cpp, forNDKthe source file.

3. encoding NDKTest.cpp

Code:

#include <string.h> #include <jni.h>extern "C" {jstring java_com_example_ndktest_mainactivity_stringjni ( jnienv* env,        jobject thiz) {                   return Env->newstringutf ("hellojni!!");}}


4. Encoding Mainactivity.java

Src->com.example.ndktest->mainactivity.java

Code:

Packagecom.example.ndktest;importandroid.support.v7.app.actionbaractivity;importandroid.os.bundle; Importandroid.view.menu;importandroid.view.menuitem;importandroid.widget.textview; Public Classmainactivity extends Actionbaractivity {static {system.loadlibrary ("Ndktest"                );                       } public native Stringstringjni (); @Override protected voidoncreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate)                    ;                    Textviewtvtext = new TextView (this);                    Tvtext.settext (Stringjni ());                 Setcontentview (Tvtext); @Override Public Booleanoncreateoptionsmenu (Menu menu) {Getmenuinflater ().                    Inflate (R.menu.main, menu);                return true; } @Override Public booleanonoptionsitemselected (MenuItem item) {int id =Item.getitemid ();                    if (id ==r.id.action_settings) {return true;               } return super.onoptionsitemselected (item); }    }


5. Compile and run, then.

problems may occur: unable to launch Cygpath. is Cygwin onthe path? Error

Solution:

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


Click on environment in the C + + build, click Add ... Add the environment variable ndkroot, which is the root directory of the NDK.

6. Mobile Phone Running Program

You can select the virtual machine AVD or connect directly to your phone. The AVD run configuration is cumbersome and it is recommended to connect directly to your phone. (reference URL http://jingyan.baidu.com/album/6181c3e0618b18152ff15375.html?picindex=4)

Open the Eclipse project, select the Runconfigurations option in run as, and in target, remove the third option and select the first option. Then apply, then OK.




To execute the project, you can see the connected phone, select the phone, and debug.



--@zl

June 2015 on 30


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

Android Environment Build Ndk+adt (free Cywgin)

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.