简体   繁体   English

Android Gradle同步失败(从github导入项目)

[英]Android Gradle sync failed (import project from github)

Hi guys i download a project from github and i imported in android studio , after imported am getting error 嗨,大家好,我从github下载了一个项目,并在导入时出现错误后导入了android studio

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: Gradle文件:

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?. 有没有人有什么建议?。

In the root folder of your project, you should have keystore.properties and local.properties files. 在项目的根文件夹中,应该具有keystore.propertieslocal.properties文件。

keystore.properties should have something like this: keystore.properties应该具有以下内容:

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

In local.properties , add the last line. local.properties添加最后一行。

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块,使gradle脚本与标准脚本相同:

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'
        }
    }
}

When I got such an error, it was because I was using JDK8, while the imported github repo was using JDK7. 当我遇到这样的错误时,这是​​因为我正在使用JDK8,而导入的github存储库正在使用JDK7。

Also make sure you have "Android Support Repository" installed from SDK Manager > Extras. 另外,还要确保您已从SDK Manager> Extras安装了“ Android支持存储库”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM