未知的“LibraryVariants"属性 - Gradle 不会同步 [英] Unknown 'LibraryVariants' property - Gradle will not sync

查看:51
本文介绍了未知的“LibraryVariants"属性 - Gradle 不会同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长话短说:我正在将一个 Android 应用程序从使用 Azure 移动应用程序服务更改为使用 Google Firebase.Firebase 设置 Javascript 非常简单直接,但我在设置 Android 时遇到了无穷无尽的问题.

Long story shortened: I am changing an android app from using Azure mobile app services to use Google Firebase. Firebase was really easy and straight forward to get setup for Javascript but I have been having endless problems with getting Android setup.

我的应用程序有三个模块:Full、Lite 和充当库的第三个模块.我正在尝试设置应用程序,以便完整版本支持 Firebase,我使用 Android Studio 中内置的助手进行了设置.这样做后,这不会构建,因为添加的 JSON 文件仅包含完整版本的包名称.我最终在 Firebase 控制台中创建了 3 个版本的应用程序,并手动将 JSON 文件添加到项目(net.gptiming、net.gptiming.full 和 net.gptiming.library).这似乎有效 - 我可以使用 Firebase 库和构建的程序.

My app has three modules: Full, Lite and a third module which acts as a library. I am trying to setup the app so that the full version has Firebase support and I did so using the assistant built into Android studio. After doing so this wouldn't build because the JSON file that was added only included the full version package name. I ended up creating 3 versions of the app in the Firebase console and manually adding the JSON file to the project (net.gptiming, net.gptiming.full and net.gptiming.library). This appears to have worked - I can use the Firebase libraries and the program built.

我发现的下一个问题是 Firebase 无法初始化 - 经过几个小时的 Google 和 stackoverflow 搜索后,我发现这可能是由于库不匹配造成的.我的第一步是更新 Android Studio(到 2.3.2)以及最新的 Google 存储库和构建工具.

The next problem I found was that Firebase was failing to initialize - After several more hours of trawling Google and stackoverflow I found that this could be due to mismatched libraries. My initial step was to update Android studio (to 2.3.2) and the latest Google repositories and build tools.

现在这又产生了另一个问题 - 我在网上似乎找不到任何地方.由于以下错误,Gradle 将不会同步:

Now this yielded yet another issue - One that I cannot seem to find anywhere online. Gradle will not sync due to the following error:

"Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension"

此错误显示在包含以下内容的库模块 gradle 构建文件中:

This error is showing in the library module gradle build file which contains the following:

apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    buildToolsVersion '23.0.2'
}

dependencies {
    compile 'com.google.code.gson:gson-parent:2.7'
    compile 'com.google.firebase:firebase-core:10.2.1'
    compile 'com.google.firebase:firebase-database:10.2.1'
    compile 'com.google.firebase:firebase-auth:10.2.1'
}

apply plugin: 'com.google.gms.google-services'

项目gradle文件如下:

The project gradle file is as follows:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter()
    }
}


ext {
    compileSdkVersion = 19
    buildToolsVersion = "23.0.2"
    storeFilePath = System.getenv('STORE_FILE')
    storePassword = System.getenv('STORE_PASSWORD')
    keyAlias = System.getenv('KEY_ALIAS')
    keyPassword = System.getenv('KEY_PASSWORD')
}

这里是完整版的模块文件:

and here is the full version module file:

apply plugin: 'com.android.application'

dependencies {
    compile project(':gptiming-gptiming')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.firebase:firebase-database:10.2.1'
    compile 'com.google.firebase:firebase-auth:10.2.1'
}

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    if (rootProject.storeFilePath) {
        signingConfigs {
            release {
                storeFile file(rootProject.storeFilePath)
                storePassword rootProject.storePassword
                keyAlias rootProject.keyAlias
                keyPassword rootProject.keyPassword
            }
        }
        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
        }
    }
    buildToolsVersion '25.0.0'
}
apply plugin: 'com.google.gms.google-services'

到目前为止,我已经尝试将 Gradle 版本更改为 2.3,但是 Android studio 2.3.2 将不支持旧的 Gradle 版本.我还尝试将构建工具版本更改为上面显示的版本,但没有任何区别.Android studio 没有提供关于这个问题的额外帮助.

So far I have tried changing the Gradle version to 2.3 however Android studio 2.3.2 will not support the older Gradle version. I have also tried changing the build tools versions to the ones shown above which made no difference. Android studio offered no additional help on the problem.

抱歉问了这么长的问题,但在 Android 开发方面我是个菜鸟 - 我不完全理解库方面如何与 Gradle 相关以及如何正确集成 Firebase,因为文档有点稀疏且内置工具没有用.我不知道该错误是否与 Firebase 有关,或者它是否只是一个简单的 Gradle 不匹配,但我们将不胜感激!

Sorry for the long question but I am a rookie when it comes to Android development - I dont completely understand how the library aspect works with respect to Gradle and how to integrate Firebase correctly as the documentation is a little sparse and the built in tools are of no use. I do not know if the error has anything to do with Firebase or whether it is just a simple Gradle mismatch but any help would be much appreciated!

我应该说在更新 Android Studio 和相关工具的版本之前我对这个库结构没有问题 - 但是这可能被 Firebase 库问题掩盖了.该应用程序在这些更改之前与 Azure 配合使用

I should say that I had no problem with this library structure before updating the version of Android studio and the associated tools - however this could have been masked by the Firebase library issues. The app worked with Azure before these changes

推荐答案

我的库模块遇到了同样的问题,并通过更新 gradle 和 google-services 版本解决了这个问题.

I had the same problem with my library module and solved it updating gradle and google-services versions.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:3.1.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
}

这篇关于未知的“LibraryVariants"属性 - Gradle 不会同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆