1.下载Catcake:

主页:http://code.google.com/p/catcake/

svn下载:svn checkouthttp://catcake.googlecode.com/svn/trunk/ catcake-read-only


2.导入Eclipse:

hello_catcake的例子程序在这个路径:catcake-read-only/sample/project/android/hello_catcake

导入直接运行不能成功,因为没有编译出需要的库


3.用ndk编译库

用cygwin进入这个路径:catcake-read-only/sample/project/android/hello_catcake/jni

运行ndk-build命令


我这里出现了错误,说找不到头文件:

cly@topgun /cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni
$ ndk-build
Compile++ thumb : hello_catcake <= main.cpp
G:/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni/main.cpp:24:26: error: catcake_main.h: No such file or directory
G:/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni/main.cpp:30: error: ISO C++ forbids declaration of 'ckMain' with no type
G:/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni/main.cpp: In function 'int ckMain()':
G:/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni/main.cpp:32: error: 'ckCreateCatcake' was not declared in this scope
G:/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni/main.cpp:40: error: 'ckResMgr' has not been declared
G:/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni/main.cpp:41: error: 'ckResMgr' has not been declared
G:/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni/main.cpp:49: error: 'ckStartCatcake' was not declared in this scope
/cygdrive/g/android-ndk-r7b/build/core/build-binary.mk:243: recipe for target `/cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/obj/local/armeabi/objs/hello_catcake/main.o' failed
make: *** [/cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/obj/local/armeabi/objs/hello_catcake/main.o] Error 1


打开Android.mk文件发现这一行:

LOCAL_C_INCLUDES := apps/catcake/include

从工程中可以看到,include目录在上一层目录中,与jni目录同等级,因此把这一行改成:

LOCAL_C_INCLUDES := ../include


再执行ndk-build

又出现错误:

cly@topgun /cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni
$ ndk-build
Compile++ thumb : hello_catcake <= main.cpp
Compile++ thumb : hello_catcake <= hello_catcake.cpp
SharedLibrary : libhello_catcake.so
G:/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: cannot find -lcatcake
collect2: ld returned 1 exit status
/cygdrive/g/android-ndk-r7b/build/core/build-binary.mk:314: recipe for target `/cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/obj/local/armeabi/libhello_catcake.so' failed
make: *** [/cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/obj/local/armeabi/libhello_catcake.so] Error 1


连接器找不到lcatcake库。


看了工程中的lib目录,发现有这个库:

libcatcake.a, libfreetype.a, libpng.a, libz.a


再查看Android.mk文件,到这一行:

LOCAL_LDLIBS := -Lapps/catcake/lib -lcatcake -lfreetype -lpng -lz -lGLESv1_CM -lgcc

跟第一次出现的头文件找不到错误一样,路径有问题,改为:

LOCAL_LDLIBS := -L../lib -lcatcake -lfreetype -lpng -lz -lGLESv1_CM -lgcc


再运行ndk-build,编译成功:

cly@topgun /cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android/hello_catcake/jni
$ ndk-build
Compile++ thumb : hello_catcake <= main.cpp
Compile++ thumb : hello_catcake <= hello_catcake.cpp
SharedLibrary : libhello_catcake.so
Install : libhello_catcake.so => libs/armeabi/libhello_catcake.so


4.Eclipse运行为Android程序:

发现程序运行一闪而过。


看程序代码,发现在main.cpp中,有这么一段

/*
The resource files need to be copied to the target by using 'adb push' command like this:
adb push hello_catcake/data /data/data/catcake_application.hello_catcake/data


And they must be specified by the absolute paths in ckResMgr::loadResource.
*/
ckResMgr::loadResource("/data/data/catcake_application.hello_catcake/data/catcake_logo_71x14.png", true);
ckResMgr::loadResource("/data/data/catcake_application.hello_catcake/data/stonsans.ttf", true);


于是在hello_catcake目录的上级目录中运行adb push hello_catcake/data /data/data/catcake_application.hello_catcake/data命令

结果如下:

cly@topgun /cygdrive/g/3D/CatCake/catcake-read-only/sample/project/android
$ adb push hello_catcake/data /data/data/catcake_application.hello_catcake/data
push: hello_catcake/data/stonsans.ttf -> /data/data/catcake_application.hello_catcake/data/stonsans.ttf
push: hello_catcake/data/catcake_logo_71x14.png -> /data/data/catcake_application.hello_catcake/data/catcake_logo_71x14.png
2 files pushed. 0 files skipped.
1294 KB/s (15911 bytes in 0.012s)


点手机上的apk运行,运行成功,但界面有些错乱重叠,如下图:



感觉是分辨率有些问题,看代码main.cpp中,有这么一句:

ckCreateCatcake("Hello Catcake", 320, 480, 30);

于是改为我手机的分辨率480,854,重新编译库和apk,运行正常,结果如下:



5.疑问:

catcake怎么用这么种资源管理方式?

编译出一个apk,还得另外把资源文件导进去,这在产品上怎么用?

看来还需要研究,肯定不会只是这种方式。


更多相关文章

  1. 【Android(安卓)应用开发】 Android(安卓)APK 反编译 混淆 反编
  2. Android(安卓)4.0.3 源码编译中添加外部jar包和外部so到apk的方
  3. android linux 基础知识总结
  4. Android的res目录
  5. Android(安卓)ndk下编译libcurl
  6. Android—— 4.2 Vold挂载管理_主体构建main (一)
  7. Android预安装软件&adb命令&编译源码
  8. Android系统权限和root权限大全
  9. 编译用于Android的FFmpeg&x264

随机推荐

  1. QuickSand图片点击后分裂成几份消失效果
  2. android小特效(持续更新...)
  3. 新建Android项目的时候,选择SDK的区别
  4. Appium元素定位(name、classname、相对路
  5. android中判断sim卡状态和读取联系人资料
  6. nodejs的交叉(跨平台)编译(to android)
  7. 【Android】强大的SpannableStringBuilde
  8. Android(安卓)Audio代码分析=Audio Strat
  9. Android(安卓)recovery流程解析
  10. android中使用adb查看sqlite数据库