build.gradle出错 - 错误:任务执行失败':app:dexDebug'

时间:2014-12-17 09:22:54

标签: android android-gradle build.gradle

我试图创建一个简单的应用程序。 我的代码很好,几天前一切都很完美。 现在我甚至无法运行我的应用程序并得到一个奇怪的错误。 我只有一个活动,没有jar文件。 这是我的Java代码:

package binder.pictureslicense;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.Random;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void clearScreen(View view) {
        clr();
    }

    private void clr() {
        ImageView pic = (ImageView) findViewById(R.id.imageView);
        EditText txt = (EditText) findViewById(R.id.IDNumber);
        TextView txtQeus = (TextView) findViewById(R.id.txtQues);

        pic.setImageResource(R.drawable.emptyface);
        txt.setText("");
        txtQeus.setVisibility(View.INVISIBLE);
    }

    private boolean checkID() {
        EditText txt = (EditText) findViewById(R.id.IDNumber);
        int[] oneTwo = new int[]{1, 2, 1, 2, 1, 2, 1, 2};
        int[] IDArr = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
        int sum = 0;
        String str = txt.getText().toString();
        int checkNum = Integer.parseInt(str.substring(str.length() - 1));
        str = str.substring(0, str.length() - 1);
        int num = Integer.parseInt(str);
        str = String.valueOf(num);
        int length = str.length();
        for (int i = 0; i < length; i++)
            IDArr[length - i - 1] = Integer.parseInt(str.substring(str.length() - 1 - i, str.length() - i));
        for (int i = 0; i < 8; i++) {
            int temp = oneTwo[i] * IDArr[i];
            if (temp > 9)
                temp = temp / 10 + temp % 10;
            sum += temp;
        }
        int div = sum % 10;
        div = 10 - div;
        if (div == 10)
            div = 0;
        if (div == checkNum)
            return true;
        return false;
    }

    private boolean checkLength() {
        EditText txt = (EditText) findViewById(R.id.IDNumber);
        String str = txt.getText().toString();
        if (str.length() > 9)
            return false;
        if (str.length() == 0)
            return false;
        return true;
    }

    private boolean checkNumbers() {
        EditText txt = (EditText) findViewById(R.id.IDNumber);
        String str = txt.getText().toString();
        if (str.matches("[0-9]+"))
            return true;
        return false;
    }

    public void checkIDBtn(View view) {
        if (checkLength()) {
            if (checkNumbers()) {
                if (checkID())
                    placePic();
                else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setMessage("תעודת הזהות שהזנת אינה תקינה").setTitle("תעודת זהות לא תקינה");
                    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
                    AlertDialog dialog = builder.create();
                    dialog.show();
                    clr();
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("אתה חייב להזין רק ספרות").setTitle("רק ספרות");
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
                clr();
            }
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("אתה חייב להזין מספר בעל 9 ספרות או פחות").setTitle("9 ספרות או פחות");
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
            clr();
        }
    }

    private void placePic() {
        ProgressBar circle = (ProgressBar) findViewById(R.id.circle);
        TextView txt = (TextView) findViewById(R.id.txtSearch);
        circle.setVisibility(View.VISIBLE);
        txt.setVisibility(View.VISIBLE);
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                ImageView pic = (ImageView) findViewById(R.id.imageView);
                ProgressBar circle = (ProgressBar) findViewById(R.id.circle);
                TextView txt = (TextView) findViewById(R.id.txtSearch);
                TextView txtQeus = (TextView) findViewById(R.id.txtQues);
                Random rand = new Random();
                int num = rand.nextInt(10) + 1;
                txtQeus.setVisibility(View.VISIBLE);
                circle.setVisibility(View.INVISIBLE);
                txt.setVisibility(View.INVISIBLE);
                switch (num) {
                    case 1:
                        pic.setImageResource(R.drawable.monkey1);
                        break;
                    case 2:
                        pic.setImageResource(R.drawable.monkey2);
                        break;
                    case 3:
                        pic.setImageResource(R.drawable.monkey3);
                        break;
                    case 4:
                        pic.setImageResource(R.drawable.monkey4);
                        break;
                    case 5:
                        pic.setImageResource(R.drawable.monkey5);
                        break;
                    case 6:
                        pic.setImageResource(R.drawable.monkey6);
                        break;
                    case 7:
                        pic.setImageResource(R.drawable.monkey7);
                        break;
                    case 8:
                        pic.setImageResource(R.drawable.monkey8);
                        break;
                    case 9:
                        pic.setImageResource(R.drawable.monkey9);
                        break;
                    case 10:
                        pic.setImageResource(R.drawable.monkey10);
                        break;
                    default:
                        break;
                }
            }
        }, 5000);
    }
}

这是我的XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:background="@drawable/background">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="הזן מספר תעודת זהות ותראה את התמונה המופיעה ברשיון שלך"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:layout_centerHorizontal="true" />

    <ImageView
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:id="@+id/imageView"
        android:src="@drawable/emptyface"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="אנא הזן מספר תעודת זהות"
        android:id="@+id/textView2"
        android:gravity="center"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:inputType="number"
        android:ems="9"
        android:id="@+id/IDNumber"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="30dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="חפש"
        android:id="@+id/btnSrc"
        android:onClick="checkIDBtn"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="אפס"
        android:id="@+id/btnClr"
        android:onClick="clearScreen"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/circle"
        android:visibility="invisible"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="מחפש..."
        android:id="@+id/txtSearch"
        android:visibility="invisible"
        android:layout_below="@+id/circle"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="באמת חשבת לראות את התמונה שלך ברשיון? :)"
        android:id="@+id/txtQues"
        android:gravity="center"
        android:visibility="invisible"
        android:layout_below="@+id/IDNumber"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"/>
</RelativeLayout>

我在某处读到了build.gradle文件可能存在的问题。这是我的build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "binder.picturelicense"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

最后这是我在尝试运行应用程序时看到的错误:

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Program Files (x86)\adt-bundle-windows-x86_64-20130917\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\איציק\AndroidStudioProjects\PictureLicense\app\build\intermediates\dex\debug --input-list=C:\Users\איציק\AndroidStudioProjects\PictureLicense\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    1
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.RuntimeException: C:\Users\׳?׳™׳¦׳™׳§\AndroidStudioProjects\PictureLicense\app\build\intermediates\classes\debug: file not found
        at com.android.dex.util.FileUtils.readFile(FileUtils.java:51)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:169)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:632)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.io.FileNotFoundException: C:\Users\׳?׳™׳¦׳™׳§\AndroidStudioProjects\PictureLicense\app\build\intermediates\pre-dexed\debug\support-annotations-21.0.3-7fe8a76469fdb827e43bf20f3c12ce539792c1fb.jar (‏‏למערכת אין אפשרות לאתר את הנתיב שצוין)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:215)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at java.util.zip.ZipFile.<init>(ZipFile.java:159)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:632)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.io.FileNotFoundException: C:\Users\׳?׳™׳¦׳™׳§\AndroidStudioProjects\PictureLicense\app\build\intermediates\pre-dexed\debug\internal_impl-21.0.3-ce53b1f9c132dc5c40800ec01310f130b6feab68.jar (‏‏למערכת אין אפשרות לאתר את הנתיב שצוין)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:215)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at java.util.zip.ZipFile.<init>(ZipFile.java:159)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:632)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.io.FileNotFoundException: C:\Users\׳?׳™׳¦׳™׳§\AndroidStudioProjects\PictureLicense\app\build\intermediates\pre-dexed\debug\classes-c4b80566cca6170006eb51a8b9aeaf044ce0b759.jar (‏‏למערכת אין אפשרות לאתר את הנתיב שצוין)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:215)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at java.util.zip.ZipFile.<init>(ZipFile.java:159)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:632)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.io.FileNotFoundException: C:\Users\׳?׳™׳¦׳™׳§\AndroidStudioProjects\PictureLicense\app\build\intermediates\pre-dexed\debug\classes-0289a8c73d1101ca747c692245c99e262ab5b2b9.jar (‏‏למערכת אין אפשרות לאתר את הנתיב שצוין)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:215)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at java.util.zip.ZipFile.<init>(ZipFile.java:159)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:632)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    5 errors; aborting

我需要改变什么? 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

为依赖项添加支持注释

compile 'com.android.support:support-annotations:21.0.+