eclipse in android,Compile C/C++ In Eclipse for Android

Software Version:

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 that you had better install the full package and from the local.

0818b9ca8b590ca3270a3433284dd417.png

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.

0818b9ca8b590ca3270a3433284dd417.png

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:\cygwin\bin,x:\cygwin is your cygwin install folder。

My is f:\cygwin.Then PATH=f:\cygwin\bin.

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

0818b9ca8b590ca3270a3433284dd417.png

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:

0818b9ca8b590ca3270a3433284dd417.png

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

0818b9ca8b590ca3270a3433284dd417.png

click OK,then you will see the next:

0818b9ca8b590ca3270a3433284dd417.png

click next to install them.

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

0818b9ca8b590ca3270a3433284dd417.png

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.

0818b9ca8b590ca3270a3433284dd417.png

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:\Android\android-ndk-r8

Edit file \cygwin\home\user_name\.bash_profile,if you can't find the file in this location,copy the cygwin\etc\skel\.bash_profileto here,add the following to the end:

0818b9ca8b590ca3270a3433284dd417.png

# Android NDK

NDK=/cygdrive/

export NDK

My:

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

export ndk

0818b9ca8b590ca3270a3433284dd417.png

ndk is a custom name ,you can change it.

Save and restart cygwin.Go to D:\Android\android-ndk-r8\samples\hello-jni\jni :

cd $ndk/samples/hello-jni/jni

0818b9ca8b590ca3270a3433284dd417.png

execute command:$ndk/ndk-build

0818b9ca8b590ca3270a3433284dd417.png

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:

0818b9ca8b590ca3270a3433284dd417.png

⑤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 of cygwin/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:\Android\android-ndk-r8) to the environment PATH.

0818b9ca8b590ca3270a3433284dd417.png

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

0818b9ca8b590ca3270a3433284dd417.png

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.

0818b9ca8b590ca3270a3433284dd417.png

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

D.Show Chinese in Cygwin

Right Click->Options:

0818b9ca8b590ca3270a3433284dd417.png

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

inttest() {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.

0818b9ca8b590ca3270a3433284dd417.png

⑦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 to coordinate with android.

0818b9ca8b590ca3270a3433284dd417.png

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

To use the lib:

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值