java.lang.RuntimeException:没有创建dex文件

时间:2016-04-17 07:30:54

标签: java android android-4.4-kitkat

我重做了Android Studio 2.0的全新安装,并创建了一个使用KitKat开始空活动的新项目。一旦我尝试运行我的应用程序,就会抛出此异常:

  

任务':app:transformClassesWithDexForDebug'执行失败。   com.android.build.api.transform.TransformException:java.lang.RuntimeException:java.lang.RuntimeException:没有在D:\ FooBar \ app \ build \ intermediates \ transforms \ dex \ debug \ folders \ 1000 \创建的dex文件10 \即时run_f87637c93f940f7e851927751cc4a5b7e4ab0be3

我到处寻找,例如添加" multiDexEnabled true"到我的模块build.gradle中的defaultConfig块。但是,我似乎无法找到类似的问题,现有的解决方案似乎也无法解决我的问题。

我附上了我能想到的所有可能有助于解决此问题的最新代码和配置文件。

这是我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.joseph.foobar">

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
        </activity>
    </application>
</manifest>

我的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ScrollScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
    <RelativeLayout
        android:id="@+id/MainLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        tools:context="com.joseph.foobar.MainActivity">
        <TextView
            android:id="@+id/MainTitle"
            android:text="@string/app_name"
            android:gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:textColor="#ffffff"/>
    </RelativeLayout>
</ScrollView>

我唯一的类MainActivity.java

package com.joseph.foobar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate()");

        setContentView(R.layout.activity_main);

        RelativeLayout container = (RelativeLayout)findViewById(R.id.MainLayout);
        Button button = new Button(this);
        RelativeLayout.LayoutParams params4 = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        params4.addRule(RelativeLayout.BELOW, R.id.MainTitle);
        params4.addRule(RelativeLayout.CENTER_HORIZONTAL);
        button.setLayoutParams(params4);
        container.addView(button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(view.getContext(), MainActivity.class);
                startActivity(intent);
            }});
    }

    @Override
    protected void onPause() {
        Log.d(TAG, "onPause()");
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume()");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d(TAG, "onStart()");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy()");
    }

    @Override
    public void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart()");
    }

    private static final String TAG = "FooBarMain";
}

我的模块build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.joseph.foobar"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
}

我的项目build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

1 个答案:

答案 0 :(得分:0)

对于删除错误临时我只需关闭android studio的即时运行功能。如果你想禁用即时运行:

1) File => Setting.

2) Click to Build,Execution,Deployment.

3) Click Instant Run

4) Uncheck to Enable Instant Run to hot swap code.....

如果您想要启用Instant Run,请执行以下操作:

1) File => Setting.

2) Click to Build,Execution,Deployment.

3) Click Instant Run

4) check to Enable Instant Run to hot swap code.....
相关问题