我正在尝试创建一个只显示片段的非常简单的程序,但每次尝试构建应用程序时都会收到错误
这是错误
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException:无法运行命令: C:\ Users \ user2435 \ Android Studio \ sdk \ build-tools \ 19.1.0 \ dx.bat --dex --num-threads = 4 --output C:\ Users \ user2435 \ AndroidStudioProjects \ TheSingleFragment \ app \ build \ intermediates \ dex \ debug C:\ Users \ user2435 \ AndroidStudioProjects \ TheSingleFragment \ app \ build \ intermediates \ classes \ debug C:\ Users \ user2435 \ AndroidStudioProjects \ TheSingleFragment \ app \ build \ intermediates \ dependency-cache \ debug C: \ Users \ user2435 \ AndroidStudioProjects \ TheSingleFragment \ app \ build \ intermediates \ pre-dexed \ debug \ android-support-v4-0c4016dfc8794ad67faea3f8cc8fd3b23877990c.jar C:\ Users \ user2435 \ AndroidStudioProjects \ TheSingleFragment \ app \ build \ intermediates \ pre-dexed \ debug \ classes-246e6497d26ce8d821cff4be0c3f291182761f73.jar C:\ Users \ user2435 \ AndroidStudioProjects \ TheSingleFragment \ app \ build \ intermediates \ pre-dexed \ debug \ support-v4-19.1.0-2cb0dcfa5e76d3d31cbc2cb35eb1e5ce1cc3a125.jar 错误代码: 2 输出: 意外的顶级例外情况: com.android.dex.DexException:多个dex文件定义了Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat $ AccessibilityServiceInfoVersionImpl; 在com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) 在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) 在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) 在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) 在com.android.dx.merge.DexMerger.merge(DexMerger.java:188) 在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) 在com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) 在com.android.dx.command.dexer.Main.run(Main.java:230) 在com.android.dx.command.dexer.Main.main(Main.java:199) 在com.android.dx.command.Main.main(Main.java:103)
以下是活动:
package com.whosaidthat.endos.thesinglefragment;
import android.app.Activity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MyActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
MyFragment myFragment = new MyFragment();
fragmentTransaction.add(R.id.fragmentContainer, myFragment);
fragmentTransaction.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是应该显示的片段
package com.whosaidthat.endos.thesinglefragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by user2435 on 23/07/2014.
*/
public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_single, container, false);
}
}
为什么会发生这种情况的任何想法,我试图用我的nexus 7设备进行测试。 如果它有帮助,我还将我的sdk文件夹中的支持.jar文件添加到libs文件夹中,因为我被告知我需要这样做才能使用支持文件
由于
答案 0 :(得分:2)
尝试构建>清洁项目。
如果这不起作用,请转到项目文件夹中的.iml(app.iml)文件,并检查支持库是否有任何重复...例如:
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
如果存在重复(或类似的看起来......可能是不同的版本),请删除其中一行,然后执行干净重建。
如果你没有看到重复,我不知道给出的信息是什么问题。
祝你好运!