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

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

问题描述

长话短说:我正在改变使用Azure移动应用服务的Android应用使用Google Firebase。 Firebase非常容易且直接地为Javascript设置,但是我一直在使用Android设置时遇到无穷无尽的问题。



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



我发现的下一个问题是Firebase未能初始化 - 经过几个小时拖网谷歌和stackoverflow我发现这可能是由于不匹配的库。
我的第一步是更新Android studio(到2.3.2)和最新的Google存储库和构建工具。

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

 无法为com.android类型的对象获取未知属性'LibraryVariants' .build.gradle.LibraryExtension

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

  apply plugin:'com.android.library'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
buildToolsVersion '23 .0.2'
}

依赖项{
编译'com.google.code.gson :gson-parent:2.7'
compile'c​​om.google.firebase:firebase-core:10.2.1'
compile'c​​om.google.firebase:firebase-database:10.2.1'
编译'com.google.firebase:firebase-auth:10.2.1'
}

应用插件:'com.google.gms.google-services'
code>

项目gradle文件如下:

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

allprojects {
存储库{
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')
}

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

  apply plugin:'com。 android.application'

dependencies {
compile project(':gptiming-gptiming')
编译fileTree(dir:'libs ,包括:['* .jar'])
编译'com.google.firebase:firebase-database:10.2.1'
compile'c​​om.google.firebase:firebase-auth:10.2.1 '
}

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

if(rootProject.storeFilePath){
signatureConfigs {
release {
storeFile文件(rootProject.storeFilePath)
storePassword rootProject.storePassword
keyAlias rootProject.keyAlias
keyPassword rootProject.keyPassword
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
buildToolsVersion '25 .0.0'
}
应用插件:'com.google.gms.google-services'

到目前为止,我已经尝试改变Gr adle版本为2.3,但Android studio 2.3.2将不支持较早的Gradle版本。我也尝试将构建工具版本更改为上面显示的版本,这些版本没有什么区别。 Android工作室在这个问题上没有提供额外的帮助。



对于长问题抱歉,但我是Android开发的新手 - 我没有完全理解库方面对Gradle的工作方式,以及如何整合Firebase正如文档有点稀疏并且内置工具是没有用的。我不知道这个错误与Firebase有什么关系,或者它只是一个简单的Gradle不匹配,但任何帮助都将非常感谢!



我应该说我在更新Android工作室版本和相关工具之前,此库结构没有问题 - 但是,这可能已被Firebase库问题所掩盖。该应用程序在Azure之前进行了这些更改

解决方案

我遇到与我的库模块相同的问题并解决了更新gradle和google-服务版本。

  //顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。 
buildscript {
repositories {
google()
jcenter()
}
依赖关系{
classpath'com.android.tools.build :gradle:3.0.0'
classpath'com.google.gms:google-services:3.1.1'
//注意:不要在这里放置您的应用程序依赖关系;它们属于单个模块build.gradle文件中的
//
}
}

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

任务清理(类型:删除){
删除rootProject.buildDir
}


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.

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.

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.

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"

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'

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'

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.

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!

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

解决方案

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天全站免登陆