java.lang.RuntimeException : No dex files created at

标签 java android android-4.4-kitkat

我重新安装了 Android Studio 2.0,并创建了一个使用 KitKat 从空 Activity 开始的新项目。当我尝试运行我的应用程序时,它会抛出此异常:

Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: No dex files created at D:\FooBar\app\build\intermediates\transforms\dex\debug\folders\1000\10\instant-run_f87637c93f940f7e851927751cc4a5b7e4ab0be3

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

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

这是我的 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
}

最佳答案

要删除临时错误,我只需关闭 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.....

如果您想启用即时运行,只需执行以下操作:

1) File => Setting.

2) Click to Build,Execution,Deployment.

3) Click Instant Run

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

关于java.lang.RuntimeException : No dex files created at,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36673826/

相关文章:

java - 查询索引数据库的java代码与查询未索引数据库的java代码相同吗?

android - 如何获取 4.4 kitkat 上的铃声 URI

java - 我可以在 Java 源文件中有宏吗

Java:多个套接字发送和接收在单个线程中维护

Android - 使用 "Set Wallpaper" Intent 设置墙纸

android - 在 Lollipop 中获取键盘高度

android - 带有 KitKat 的 Android 设备上的 java.lang.NoClassDefFoundError

java - Spring示例应用程序不考虑tomcat应用程序路径

java - 将字符串转换为 jsonobject 时出现异常

android - 如何在 ViewPager 中添加自定义 View 以进行演练