import org.cocos2dx.lib cannot be resolved

在使用 cocos2dx 的时候,建立的工程在编译的时候提示 import org.cocos2dx.lib cannot be resolved ,研究了研究发现,工程里面缺少了相应的Java代码,目录都已经建立好了,但是似乎拷贝脚本出了问题,没有把源文件拷贝进去

解决方法就是 ,找到 cocos2dx 的释放目录,在目录下找到 cocos2dx目录 下面找到 platform 目录下面有个android 目录 下面有个java目录,如下图了

我们在工程目录下面也看到一个类似的空目录

对应的目录拷贝进去就可以了

Android NativeActivity samples crashes

Log

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.
native_activity/android.app.NativeActivity}: java.lang.IllegalArgumentException
: Unable to find native library: native-activity

Answer

Over!

Type 'EGL_DEFAULT_DISPLAY' could not be resolved error while constant is clearly defined

I'm working on a native activity app for Android 2.3.3. I've copied the code from the code samples, I have include paths set, but Eclipse (Indigo) still can't find this constant.

EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);//Type 'EGL_DEFAULT_DISPLAY' could not be resolved

However the compiler shows no error:

Compile++ thumb  :NativeTest<=NativeTest.cpp

This error has to do with Eclipse not having __ ANDROID__ defined which makes it not define EGLNativeDisplayType in EGL/eglplatform.h which causes EGL_DEFAULT_DISPLAY to also not be defined.

To fix this go to your projects properties and go to the "C/C++ General->Paths and Symbols" page, under the "Symbols" tab click on GNU C and then the "Add" button and put

__ANDROID__

in the name feild and click OK. You can do the same for GNU C++.

The 'adb' tool is not in your path. You can change your PATH variable, or use --adb= to point to a valid one

The ndk-gdb script relies on setting the adb path, either by setting it as
an environment variable or
explicitly as a parameter of the script call.
Thus, there are two probable solutions:

1) set the PATH environment variable to point out your android sdk tools
folder (e.g. "export PATH=$PATH:<your_android_sdk_path_here>/tools")

or

2) invoke the ndk-gdb command with the path to the adb as a parameter (e.g.
: "ndk-gdb --adb=<your_android_sdk_path_here>/tools/adb")

keep in mind that the 1) solution will only work for your current terminal
session. If you want to persist this new PATH value, you must set it up
in the ~.MacOSX/environment.plist.

Android+Eclipse,创建项目总是出现 invalid project description. overlaps the workspace location的解决办法

创建或者导入工程的时候总是提示invalid project description. overlaps the workspace location错误,到处查资料最后找到解决办法,就是把新创建的工程目录设为非Eclipse得workspace目录,具体原因未知。

Ubuntu 12.04下"小米2"的真机调试

发现Ubuntu12.04不能连接小米开发,adb devices不能看到设备!  搞了一个上午才搞成功!

小米手机利用USB连接到Ubuntu 12.04系统。运行下面的命令:

拔掉手机的USB连接线,再运行:

对比发现,Bus 002 Device 028: ID 2717:904e    就是小米手机的

在打开的文件中增加以下文本:

注意,这个50-android.rules 文件名字应该是随意命名的,试过 51-android.rules ,52-android.rules  似乎是都可以的。

注意 "SUBSYSTEM=="usb", SYSFS{idVendor}=="2717", MODE=="0666" "这句是给 ubuntu 7.01 以后的系统识别用的

而"SUBSYSTEM=="usb_device", SYSFS{idVendor}=="2717", MODE=="0666""是给 Ubuntu 7.01之前的系统识别用的。相当于系统兼容。

在 android sdk 的 tools 目录下运行 (这一步很重要,必须要sudo,否则没效果)

到这一步了,结果发现 List of devices attached 下面没有设备出现,这就意味着 adb不识别新的USB 设备,纠结了。

如果跟我一样悲惨,请执行如下操作

请注意这个 adb_usb.ini

里面的内容一般如下:

我们在其中加一行

请注意,这个 0x2717 就是我们得到的设备号码

保存,关掉,然后

注意  9109ce53    device 这行就是我们的识别到的小米手机了。哈哈

然后在Eclipse下面的DDMS 去折腾吧。

gen already exists but is not a source folder. Convert to a source folder or rename it.

Android 代码中无意删除了 .setting文件夹,重建后提示

gen already exists but is not a source folder. Convert to a source folder or rename it.

查了半天,总算有个明白人

  1. Right click on the project and go to "Properties"
  2. Select "Java Build Path" on the left
  3. Open "Source" tab
  4. Click "Add Folder..."
  5. Check "gen" folder and click Ok and Ok again
  6. Again right click on the project and in the "Andriod Tools" click on "Fix Project Properties"

Android:多语言对应

我们建好一个android 的项目后,默认的res下面 有layout、values、drawable等目录

这些都是程序默认的资源文件目录,如果要实现多语言版本的话,我们就要添加要实现语言的对应的资源文件。

首先我们点击添加Android Xml File按钮,会出现下面的界面:

image

输入文件名:string.xml,选中Values单选框,并把下面左列表中的Region添加到左边的列表里面,并在Region输入框里输入cn,如下图

image

这时,上面的消息提示:如果用Region的话,需要使用语言项,和Region一样,我们把Language也添加到右面的列表里面,填入zh,如下图

image

点击Finish按钮,资源文件就会建好了,目录:res\values-zh-rCN(其实上面一大堆操作,就是为生成这个目录

image

默认生成的string.xml的代码:

修改刚刚生成的res\values-zh-rCN目录下的string.xml:

运行结果:

en-us:英文

imageimage

zh-cn:中国大陆

imageimageimage

zh-tw:台湾

imageimageimage

因为设置了region为CN,所以zh-tw的时候,没有找到res\values-zh-rTW的目录,加载了默认的res\values目录下的string.xml

这里只用了Values做例子,其余的Resource都可以,图片了,布局了等等

这里只是简单的介绍了一下多语言对应,剩下的大家自己深入研究吧!

Eclipse调试应用的时候显示Android源代码

在用Eclipse 调试程序的时候,一旦发生异常,往往在回退栈里面提示找不到源代码.

如下图所示

网 上搜索了一下,发现一个 fix_android_sdk.py 脚本,可以提取完整的java 文件到SDK 目录,尝试了一下,还是蛮有用的,可惜就是源代码只能看,不能设置断点。这个是用来编译ASE的一个脚本,里面的部分涉及到ASE的部分我们是用不到,并 且也没法用的,所以被我万恶的删除了。

1.首先要下载完整的Android源代码,建议下载一下,说不定哪天就用上了。

对 于以前的脚本进行了修改,然后现在可以判断当前的Android 的源代码版本了,如果定义过 "ANDROID_SDK_ROOT"环境变量的话,会使用环境变量中的值拷贝到制定的目录,比如Android 4.1.2 的源代码,现在可以拷贝到 Android-16 目录下面了,不需要再从android-1.5 下面拷贝出来了。 下面贴上最新的源代码脚本,供各位参考。