Compile C/C++ In Eclipse for Android


Software Version:

*Cygwin 1.7.15-1*

Eclipse IDE for C/C++ Developers(Juno)

Eclipse Classic 4.2 (Juno)

CDT 8.1.0 for Eclipse Juno

Android ADT 14.0.0

Android SDK 4.0.3 (API 15)

Android NDK r8

A.Eclipse IDE for C/C++ Developers + Cygwin

Install Eclipse IDE for C/C++ Developers.

Install Cygwin.Important step!You had better download the full package and install from local.Installing from Internet always failed and may lost file!

The first time I install it from the Internet ,but it occured a file failure and I ignore it.Then ,holy shit!!! I spend 2 days to debug the errors result from the file failure!!So remember thatyou had better install the full package and from the local.

Compile C/C++ In Eclipse for Android

click the "Install" after "All".

Install/Download from Internet.If the warning “Download Incomplete,Try again? ” comes out or it hangs on a certain progress,you can cancel it and repeat the download steps.Remember two points:

Ⅰ.Select the same download website with the last time.

Ⅱ.Installing type,select ”Reinstall“ not ”install“.(may needn't)

Then you can continue the download progress or you have to install from 0.

Compile C/C++ In Eclipse for Android

I download it first for a night and then install it for a day.A whole day!

Probably you have to set theenvionment variable PATH。PATH should include x:cygwinbin,x:cygwin is your cygwin install folder。

My is f:cygwin.Then PATH=f:cygwinbin.

Restart Eclipse,File->New->C++ Project

Compile C/C++ In Eclipse for Android

click Finish,Build it first and then run it.


B.Eclipse Classic+Cygwin+CDT

Install Eclipse Classic 4.2.

Install CDT for Eclipse.

Open the CDT download page,you will see the following content:

pic B-1

The p2 software repository is the address you should access in Eclipse.Help->Install New Software,click Add button and input the address:

Compile C/C++ In Eclipse for Android

click OK,then you will see the next:

Compile C/C++ In Eclipse for Android

click next to install them.

However,it hanged at this progress for a long time:

Compile C/C++ In Eclipse for Android

Then I canceled it ,and clicked the cdt-master-8.1.0.zip of pictrue ,wanting to download it first and install it from local directory.

Compile C/C++ In Eclipse for Android

clickArchive to select the local zip file.

Finally,I installed the CDT successfully.

*③Install Cygwin.The same with Part A*.

Restart Eclipse,File ->New -> Others,and you'll see C/C++ project.


C.Eclipse Classic+ Cygwin +CDT + NDK -> so Lib

①②③ The same with part B①②③.

Install NDK.Download the zip file and unzip it to the destination folder.my is D:Androidandroid-ndk-r8

Edit file cygwinhomeuser_name.bash_profile,if you can't find the file in this location,copy the cygwinetcskel.bash_profileto here,add the following to the end:

# Android NDK

NDK=/cygdrive/<你的盘符>

export NDK

My:

ndk=/cygdrive/D/Android/android-ndk-r8

export ndk

ndk is a custom name ,you can change it.

Save and restart cygwin.Go to D:Androidandroid-ndk-r8sampleshello-jnijni :

cd $ndk/samples/hello-jni/jni

Compile C/C++ In Eclipse for Android

execute command$ndk/ndk-build

Compile C/C++ In Eclipse for Android

Pay attention to these content of google document:

Required development tools

  • For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.
  • A recent version of awk (either GNU Awk or Nawk) is also required.
  • For Windows, Cygwin 1.7 or higher is required.The NDK will not work with Cygwin 1.5 installations.

If you installed the wrong version,you may get the error of the following pictrue:

Compile C/C++ In Eclipse for Android

CreateNDK Builder for Eclipse.

Right click your project->Properties->Builders->New->Program:

Main location:the path of file bash.exe in cygwin/bin.

workingdirectory:the path ofcygwin/bin.

arguments:--login -c "cd /cygdrive/d/Workspace2/hello&&$ndk/ndk-build"

/cygdrive/d/Workspace2/hello is the absolute path of yourandroid project.

if you can't input the argument or it can't be recognized,make sure that you have added the path of ndk (D:Androidandroid-ndk-r8) to the environment PATH.

Compile C/C++ In Eclipse for Android

In label Refresh,specific the folder needed to refresh when compilation end.Choose libs,create it if none.

Compile C/C++ In Eclipse for Android

About the label Build Options,use to set the folder needed to monitor.Run the builder when the content of the folder changed.

Specify working set... choose the folder of the c/c++ code.

Compile C/C++ In Eclipse for Android

Completed! you can use the builder in your android project.


D.Show Chinese in Cygwin

Right Click->Options:

Compile C/C++ In Eclipse for Android

Set the character set to GBK,not UTF-8

E.A Project For Test

Create a empty android project.

Create jni folder to contain c/c++ code.

Create libs folder to contain generated libs.

Write your c/c++ code in jni.

My:hello.cpp

int test() {
    return 5;
}

Write your Android.mk file.you can copy it from the ndk sample project.

Press "Ctrl+S" to save it and the lib will be generated automatically.

Compile C/C++ In Eclipse for Android

Generate the lib which can be used in android.

In order to use the lib in Android, you have to modify the C/C++ code tocoordinate with android.

Compile C/C++ In Eclipse for Android

If the package name or activity name not coordinate with c/c++ method name,UnsatisfiedLinkError may occurs.

To use the lib:

Compile C/C++ In Eclipse for Android
原文链接: https://www.cnblogs.com/qiengo/archive/2012/07/12/2587754.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/54993

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午6:08
下一篇 2023年2月9日 上午6:08

相关推荐