Android Gradle sync failed (import project from gi

2019-07-17 20:27发布

问题:

Hi guys i download a project from github and i imported in android studio , after imported am getting error

Gradle sync failed: Cause: assert localProps['keystore.props.file']
       |         |
       |         null
       [ndk.dir:E:\sdk\ndk-bundle, sdk.dir:E:\sdk]
       Consult IDE log for more details (Help | Show Log)

Gradle File:

signingConfigs {
    release {
        def Properties localProps = new Properties()
        localProps.load(new FileInputStream(file('../local.properties')))
        def Properties keyProps = new Properties()
        assert localProps['keystore.props.file'];
        keyProps.load(new FileInputStream(file(localProps['keystore.props.file'])))
        storeFile file(keyProps["store"])
        keyAlias keyProps["alias"]
        storePassword keyProps["storePass"]
        keyPassword keyProps["pass"]
    }
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
        signingConfig signingConfigs.release
    }

    publicBeta.initWith(buildTypes.release)
    publicBeta {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
        versionNameSuffix " Beta " + versionProps['betaNumber']
    }

    publicDebug.initWith(buildTypes.publicBeta)
    publicDebug {
        debuggable true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
        versionNameSuffix " Debug Beta " + versionProps['betaNumber']
    }
}

}

I realy don't know what to do.

Does anyone have any suggestions?.

回答1:

In the root folder of your project, you should have keystore.properties and local.properties files.

keystore.properties should have something like this:

store=/path/to/your.keystore
alias=your_alias
pass=your_password
storePass=your_keystore_password

In local.properties, add the last line.

ndk.dir=/Users/username/Library/Android/sdk/ndk-bundle    
sdk.dir=/Users/username/Library/Android/sdk
# Add the line below
keystore.props.file=../keystore.properties 

See a commit here or check the modified project.

Or if you need a quick dirty fix, just make the gradle script the same as a standard one by replacing the android block with this:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion

        versionCode 1
        versionName "1.0"
    }

    lintOptions {
        abortOnError false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


回答2:

When I got such an error, it was because I was using JDK8, while the imported github repo was using JDK7.

Also make sure you have "Android Support Repository" installed from SDK Manager > Extras.