Wednesday 13 August 2014

R cannot be resolved to a variable

Android开发过程中,碰到R cannot be resolved to a variable的报错信息,好像没有很确定的错误原因,一般来说,总结出几个可能的解决方法,希望试过以后管用。。。

1. 检查Android 的SDK是否丢失需要重新下载,检查build path
2.确保class没有import Android.R;
3,错误class引用的layout的xml文件没有错误
4.检查AndroidManifest.xml文件,里边的package,layout配置文件,strings.xml等的字符串全部书写正确
5.layout的xml文件中引用的strings.xml中的字符串拼写完全正确
6.在layout 的xml文件手写添加一个控件,看id能否在R.java中自动生成,如果不能,那很大可能就是这个layout 的xml文件有问题,查看格式是否使用正确,或者包含什么非法字符串,或者调用到了不正确的字符串,等等,可以使用排除法,挨个去掉控件,直到发现error message消失或者id能在R.java中自动生成。
7.删掉gen文件夹,使R.java重新自动生成一次,如果不能生成,继续检查layout的xml文件是否有如上不易发觉的问题
8.Clean project ,重新build,或者重新import project。
9.重启eclipse (restart eclipse)
10.重启电脑,解决Android 虚拟机的问题 (reboot the PC, maybe something wrong with the JAVA env )

Monday 11 August 2014

error: cannot find -lsonivox



I copied libsonivox.so into /platforms/android-14/arch-arm/usr/lib/, my android.mk file is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := midi
LOCAL_SRC_FILES := midi.c
LOCAL_LDLIBS    += -lsonivox
include $(BUILD_SHARED_LIBRARY)
but when I ran ndk-build I got this error:
.../ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lsonivox

libsonivox.so can be loaded dynamically. You need to copy the .so from your android device and place it in $NDK-ROOT/platforms/android-14/arch-arm/usr/lib, "android-14" can be whatever version instead.

So I copied libsonivox.so to "android-18" and other "android-1X", and build it again, it worked!

Friday 8 August 2014

Red exclamation mark eclipse android project

I saw a red exclamation mark today







Found some libraries are missing. So added them, solved this issue.