zoukankan      html  css  js  c++  java
  • android 导入开源项目代码常见问题

    1.Error:Unable to resolve target android-5

    解决办法:修改工程目录下的project.properties文件里的内容target=android-5数字改成你机器里装过的android SDK版本就可以了。

    附:
    使用高版本的SDK后再导入以前用低版本的project时,会遇到一些兼容性的问题。
    (1)Unable to resolve target android-5
    因为本机中现在使用的是2.1的SDK,API的版本是7;而导入的工程使用的是2.0开发的,其API版本是5。
    需要将project.properties中的target=android-5改为target=android-7就好了。
    但要注意,也要同步将AndroidManifest.xml中的<uses-sdk android:minSdkVersion="5" />也要改一下,否则编译中会警告提示使用的版本过低。
    (2)以上完成后,编译中又出现一个新的错误:Conversion to Dalvik format failed with error 1
    这个与加载的SDK有关,通过“右键选择工程build path -> configure build path... -> library发现导入的JARs中除了一个Android 2.1-update1外还有一个同路径下的文件夹item,将其移除,clean一下再编译就没问题了。

    2. SlidingMenu library project里出现的错误

    (1)

    • Console error: Unable to resolve target ‘Google Inc.:Google APIs:16.

      Fix: 进入Properties检查Target sdk是否选择了 Google APIs.

    • List of errors: ACTION_POINTER_INDEX_MASK cannot be resolved android.
      HONEYCOMB cannot be resolved or is not a field
      LAYER_TYPE_HARDWARE cannot be resolved or is not a field
      LAYER_TYPE_NONE cannot be resolved or is not a field
      MATCH_PARENT cannot be resolved or is not a field
      The method getLayerType() is undefined for the type View
      The method setLayerType(int, null) is undefined for the type View

      Fix: 将manifest里面的min sdk version 改为你当前用到的sdk版本,7以上.

    (2)修复example project里出现的错误

      • Console error: Found 2 versions of android-support-v4.jar in the dependency list,but not all the versions are identical (check is based on SHA-1 only at this time). Jar mismatch! Fix your dependencies

        Fix: 这是由于jar包版本不一致导致的,检查SlidingMenu和Actionbarsherlock中的libs文件夹里的哪个android-support-v4.jar版本比较新,用新的替换掉其中的老版本. 如果错误还是会出现,就clean项目并重启eclipse.

      • List of errors: The method getSupportActionBar() is undefined for the type BaseActivity
        The method getSupportMenuInflater() is undefined for the type BaseActivity
        The method onCreateOptionsMenu(Menu) of type BaseActivity must override or implement a supertype method
        The method onOptionsItemSelected(MenuItem) in the type Activity is not applicable for the arguments
        The method onOptionsItemSelected(MenuItem) of type BaseActivity must override or implement a supertype method
        The method onOptionsItemSelected(MenuItem) of type ResponsiveUIActivity must override or implement a supertype method

        Fix:打开SlidingMenu library project里SlidingFragmentActivity这个类并在声明前添加以下代码:

      • import com.actionbarsherlock.app.SherlockFragmentActivity;  

        然后,将下面这个父类:

      • public class SlidingFragmentActivity extends FragmentActivity implements SlidingActivityBase {  

        换成Actionbarsherlock里的另外一个父类:

      • public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {  

        如果错误还是会出现,就clean项目并重启eclipse.

    3.中文乱码问题

    (1). 设置Workspace的编码格式: 
    Windows->Preferences... 打开"首选项"窗口,点击左侧导航树到General->Workspace,在右侧视图中找到“Text file encoding”选项设置,一种是默认(Default),另一种是从下拉列表中选择(Other)。Eclipse Workspace默认的编码方式是操作系统的编码格式,这跟操作系统的设置有关系;另外我们可以选择Other单选按钮,然后从按钮右侧的下拉列表中选 择需要的编码格式(GBK、ISO-8859-1、UTF-16、UFT-16 etc.)。 
    (2). 设置Project的编码格式: 
    在 Workspace中新建的项目默认继承Workspace的编码设置,我们也可以单独更改某个项目的编码格式。右键点击工程,选择 Properties,打开项目属性设置窗口,左侧导航树选择Resource,在右侧视图中找到“Text file encoding”,两种设置项目的编码格式,默认选中的是“Inherited from container (XXX)”(注:XXX为Workspace设置的编码),我们也可以选择其他的编码格式,设置方式同Workspace。 
    (3). 设置Content Type的编码格式: 
    有 时我们想使整个Workspace某种类型的文件保持同一种编码格式,这就需要用到Content Type设置来达到目的,具体方式如下:Windows->Preferences...打开"首选项"窗口,左侧导航树选择 General->Content Types,在右侧视图中选择Text->Java Source File,在最下侧有Default encoding输入框,手动输入编码格式,点击Update按钮使设置生效(切记啊!)。有两点需要注意一下: 
    a. 这个设置使Workspace所有项目下的相同类型的文件有相同的编码格式,改变项目的编码设置不影响项目中文件类型的编码设置; 
    b. Default encoding是手动输入的,输入的编码名称要准确,否则在打开此类型文件时会显示Unsupported Character Encoding。 
    (4). 设置File的编码格式: 
    我 们还可以单独设置某个文件的编码格式,一种是通过在文件中设置编码格(如:'charset=UTF-8'),还可以通过文件属性设置。右键点击某一文 件,选择Properties,打开文件属性设置对话框,右侧导航树选择Resource,在右侧视图中通过“Text file encoding”选择设置文件的编码格式。

  • 相关阅读:
    死锁
    钩子函数和回调函数的区别
    蓝绿部署、滚动发布、灰度发布的介绍以及最佳实践
    小公司的瓶颈
    Modbus协议详解
    windows+jenkin
    Java:简单的多态实例
    一、Kubernetes系列之介绍篇
    Shell脚本自动搭建ipsec环境
    Appium(1):安卓自动化环境搭建 + Android SDK + Appium 环境搭建
  • 原文地址:https://www.cnblogs.com/liubingna/p/3377773.html
Copyright © 2011-2022 走看看