Java 使用Eclipse导入库项目时的Android问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21317101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android problems when import library project using Eclipse
提问by daiyue
So, I tried to add v7 appcompat
support library with resource to MyFirstApp
project, by following the tutorial @
因此,我尝试按照教程 @v7 appcompat
向MyFirstApp
项目添加带有资源的支持库
http://developer.android.com/tools/support-library/setup.html
http://developer.android.com/tools/support-library/setup.html
Both android-support-v4.jar
and android-support-v7-appcompat.jar
files were exported. Eclipse includes the android-support-v4.jar
by default and when I tried the code:
这两个android-support-v4.jar
和android-support-v7-appcompat.jar
文件出口。Eclipse 包括android-support-v4.jar
默认情况下,当我尝试代码时:
// MainActivity.java
import android.support.v7.app.ActionBarActivity;// error
public class MainActivity extends ActionBarActivity {...} // error
// DisplayMessageActivity.java
import android.support.v4.app.NavUtils; // error on this line
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.display_message, menu);// error at R
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);// error at NavUtils
return true;
}
return super.onOptionsItemSelected(item);
}
I got a number of errors:
我有很多错误:
The import android.support cannot be resolved MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 4 Java Problem
The method onCreate(Bundle) of type MainActivity must override or implement a supertype method MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 16 Java Problem
ActionBarActivity cannot be resolved to a type MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 12 Java Problem
R cannot be resolved to a variable MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 18 Java Problem
ActionBarActivity cannot be resolved to a type MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 17 Java Problem
The method onCreateOptionsMenu(Menu) of type MainActivity must override or implement a supertype method MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 23 Java Problem
The import android.support cannot be resolved DisplayMessageActivity.java /MyFirstApp/src/com/example/myfirstapp line 9 Java Problem
R cannot be resolved to a variable DisplayMessageActivity.java /MyFirstApp/src/com/example/myfirstapp line 51 Java Problem
The method getMenuInflater() is undefined for the type MainActivity MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 25 Java Problem
R cannot be resolved to a variable MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 25 Java Problem
The constructor Intent(MainActivity, Class<DisplayMessageActivity>) is undefined MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 30 Java Problem
R cannot be resolved to a variable MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 31 Java Problem
The method startActivity(Intent) is undefined for the type MainActivity MainActivity.java /MyFirstApp/src/com/example/myfirstapp line 34 Java Problem
Jar mismatch! Fix your dependencies MyFirstApp Unknown Android Dependency Problem
NavUtils cannot be resolved DisplayMessageActivity.java /MyFirstApp/src/com/example/myfirstapp line 66 Java Problem
When I added the library android-support-v7-appcompat
to MyFirstApp
, and apply
, I got the following errors:
当我将库添加android-support-v7-appcompat
到MyFirstApp
, 和 时apply
,出现以下错误:
[2014-01-23 18:31:52 - MyFirstApp] Found 2 versions of android-support-v4.jar in the dependency list,
[2014-01-23 18:31:52 - MyFirstApp] but not all the versions are identical (check is based on SHA-1 only at this time).
[2014-01-23 18:31:52 - MyFirstApp] All versions of the libraries must be the same at this time.
[2014-01-23 18:31:52 - MyFirstApp] Versions found are:
[2014-01-23 18:31:52 - MyFirstApp] Path: C:\Users\daiyue\Google Drive\MyFirstApp\libs\android-support-v4.jar
[2014-01-23 18:31:52 - MyFirstApp] Length: 621451
[2014-01-23 18:31:52 - MyFirstApp] SHA-1: 5896b0a4e377ac4242eb2bc785220c1c4fc052f4
[2014-01-23 18:31:52 - MyFirstApp] Path: C:\Program Files (x86)\Android\android-sdk\extras\android\support\v7\appcompat\libs\android-support-v4.jar
[2014-01-23 18:31:52 - MyFirstApp] Length: 627582
[2014-01-23 18:31:52 - MyFirstApp] SHA-1: db0f122c99ef9f90dbab3fada6d191f2880cbb8e
[2014-01-23 18:31:52 - MyFirstApp] Jar mismatch! Fix your dependencies
[2014-01-23 18:31:53 - MyFirstApp] W/ResourceType( 8160): ResXMLTree_node header size 0 is too small.
[2014-01-23 18:31:53 - MyFirstApp] C:\Users\daiyue\Google Drive\MyFirstApp\res\values\desktop.ini:1: error: Error parsing XML: syntax error
[2014-01-23 18:31:53 - MyFirstApp] C:\Users\daiyue\Google Drive\MyFirstApp\res\values-v11\desktop.ini:1: error: Error parsing XML: syntax error
[2014-01-23 18:31:53 - MyFirstApp] C:\Users\daiyue\Google Drive\MyFirstApp\res\values-v14\desktop.ini:1: error: Error parsing XML: syntax error
[2014-01-23 18:31:53 - MyFirstApp] C:\Users\daiyue\Google Drive\MyFirstApp\res\values-sw600dp\desktop.ini:1: error: Error parsing XML: syntax error
[2014-01-23 18:31:53 - MyFirstApp] C:\Users\daiyue\Google Drive\MyFirstApp\res\values-sw720dp-land\desktop.ini:1: error: Error parsing XML: syntax error
[2014-01-23 18:31:53 - MyFirstApp] C:\Users\daiyue\Google Drive\MyFirstApp\res\layout\desktop.ini:1: error: Error parsing XML: syntax error
[2014-01-23 18:31:53 - MyFirstApp] C:\Users\daiyue\Google Drive\MyFirstApp\res\menu\desktop.ini:1: error: Error parsing XML: syntax error
采纳答案by Aashir
Replace one of the specified android-support-v4.jar with the other, so that you have the same one in both places. That will resolve your issue.
将指定的 android-support-v4.jar 中的一个替换为另一个,以便在两个位置都使用相同的一个。那将解决您的问题。