Unable to build gradle and create java class

2019-03-04 05:11发布

Any project in my android studio fails to build.The error message is as follows-

Gradle sync failed: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-3.3-all.zip'.
                Consult IDE log for more details (Help | Show Log)

Moreover i'm unable to make a new java class in android studio by File->new->Java class as no such option is available. I found some answers saying right click on java folder then clicking Mark Directory as -> SOurce root, even this option is not there . Moreover, for resolving the gradle issue, i found some answers saying click File->Invalidate Caches/Restart and delete the .gradle file in home directory then update android studio, i did accordingly but still nothing works. build.gradle contents are-

apply plugin: 'com.android.application'

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
    testCompile 'junit:junit:4.12'
}

Contents of gradle-wrapper.properties are-

#Tue Mar 28 20:10:53 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

Build.grale-

// 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.3.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
}

on doing Build->Clean project this error message was shown-

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugUnitTestApkCopy'.
   > Could not resolve junit:junit:4.12.
     Required by:
         project :app
      > Could not resolve junit:junit:4.12.
         > Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
            > Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
               > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/108.168.243.150] failed: Connection timed out

I even uninstalled Android-Studio 2.3 and installed 2.2.2 instead but still the problem persists

0条回答
登录 后发表回答