Gradle sync失败并且出现许多错误,因为无法解决

时间:2017-12-27 08:00:55

标签: android android-gradle

我无法理解这是什么问题?任何人都可以帮助,附上Android Studio截图

构建成绩文件是//顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

buildscript {

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


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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

我的app build.gradle文件是

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.a479729.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Image

2 个答案:

答案 0 :(得分:0)

试试这个, 在您的顶级构建gradle

    public class HomeController : Controller
    {
    public ActionResult Login()
    {
        return View();
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Login(UserProfile objUser)
    {
        if (ModelState.IsValid)
        {
            using(DB_Entities db = new DB_Entities())
            {
                var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();

                if (obj != null)
                {
                    Session["UserID"] = obj.UserId.ToString();
                    Session["UserName"] = obj.UserName.ToString();
                    return RedirectToAction("Dashboard");
                }
                else
                {
                    ViewBag.Message = "Invalid Username or Password";
                }
            }
        }

        return View(objUser);
    }

    public ActionResult Dashboad()
    {
        if (Session["UserID"] != null)
        {
            return View();
        }
        else
        {
            return RedirectToAction("Login");
        }
    }
}

参考:https://developer.android.com/topic/libraries/support-library/setup.html

答案 1 :(得分:0)

似乎问题在于你的gradle版本。大多数情况下,当您导入其他项目时会发生此错误。因为它可以具有比您的版本更旧的gradle脚本。要升级您的gradle,请删除项目中的gradle文件。然后清洁&重建你的项目。然后android工作室要求从互联网上下载新的gradle版本。等到下载完成。它将解决gradle中的错误。

相关问题