今天导入一个项目,发现运行不能,红叉叉表示com.android.internal.R.的一系列引用都失败。
查了一下,这些都在一个SDK自带包layoutlib.jar中。SDK路径\platforms\api版本\data 下就有 layoutlib.jar
直接把这些扔到libs文件夹中,红叉叉消失,运行又报错:Conversion to Dalvik format failed with error 1
上网查了一下,大概意思是包中资源与项目资源引用冲突,于是继续查。
果然不负有心人,应该采用用户库的形式导入该库,具体步骤如下:
1. Right-click the project in Eclipse and select "Build Path -> Add Libraries...".
2. Select User Library from the list and click Next.
3. Click the "User Libraries..." button.
4. Click "New..." in the User Libraries dialog.
5. Give the user library a name and select the System library checkbox and click OK.
6. Highlight the newly added user library in the list and click the "Add JARs..." button and add the desired jar files.
7. Click OK on the User Libraries dialog.
8. Make sure the new user library is checked in the Add Library dialog and click finish.
按照上面的步骤,我命名库Layoutlib,再运行,还是报错。
仔细看了下项目中库jar包支持,发现自己的Layoutlib和系统的Android Private Libraries都引用了layoutlib.jar
把layoutlib.jar从libs中拿出来放到应用根目录,把Layoutlib库指向新路径。
运行,成功!