android - 无法解析 : project :Library:materialDrawer

标签 android android-gradle-plugin build.gradle

我正在尝试将 mikepenz 的 Material Drawer 添加为第三方项目。我想将它添加为项目的原因(不仅仅是编译为依赖项)以便我可以根据我的要求修改抽屉的 UI。但是我无法成功同步我的 gradle 并收到以下错误:

Failed to resolve:project :Library:materialDrawer

这是我的项目结构:

-> root
  ->app
     ->Library
        -> materialDrawer
              -> app
              -> build.gradle
              -> settings.gradle
  -> build.gradle(project)
  -> settings.gradle

我试着关注这个项目 https://github.com/foragerr/android-multi-project-sample/blob/master/settings.gradle但在静脉。

这是我的build.gradle(我的项目)文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.novoda:bintray-release:0.3.4'
    }
}

allprojects {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
}

settings.gradle(我的项目)

include ':app', ':Library:materialDrawer'

build.gradle(应用:我的项目)

apply plugin: 'com.android.application'
apply plugin: 'android'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.******"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 38
        versionName "2.1.8"

        generatedDensities = []

    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

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

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
/*
    compile('com.mikepenz:materialdrawer:5.6.0@aar') {
        transitive = true
    }
*/
    compile project(':Library:materialDrawer')
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.android.support:design:25.0.1'
    compile 'com.android.support:support-v4:25.0.1'
    compile 'com.android.support:recyclerview-v7:25.0.1'
    compile 'com.android.support:cardview-v7:25.0.1'
    compile 'com.google.android.gms:play-services-maps:10.2.0'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.firebase:firebase-messaging:10.2.0'
    compile 'com.google.firebase:firebase-core:10.2.0'
    compile 'com.google.firebase:firebase-crash:10.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
    compile 'com.github.ParkSangGwon:TedPermission:v1.0.12'
    compile 'hanks.xyz:smallbang-library:0.1.2'
    compile 'com.yalantis:ucrop:2.2.0'
    compile 'com.github.clans:fab:1.6.4'
    compile 'me.zhanghai.android.materialratingbar:library:1.0.2'
    compile 'com.android.support.constraint:constraint-layout:1.0.0'
}

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

build.gradle(项目:materialDrawer)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.novoda:bintray-release:0.3.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
}                  

我的 Android Studio 是 v2.3.3。我挠头但找不到任何解决方案。请有人帮助我,我坚持了三天......

最佳答案

因为您正在使用:

compile project(':Library:materialDrawer')

gradle 正在该模块中寻找 build.gradle。 检查您的问题,此文件存在但它是顶级 文件而不是模块文件

你应该以这种方式改变结构(你不应该把库文件夹放在另一个模块中)

-> root
  ->app
    -> build.gradle
  ->Library
      -> materialDrawer
           -> app
              -> build.gradle
           -> build.gradle
           -> settings.gradle
  -> build.gradle(project)
  -> settings.gradle

您必须更改 settings.gradle :

include ':app', ':materialDrawer'
project(':materialDrawer').projectDir = new File('/Library/materialDrawer/app')

然后作为依赖使用:

compile project(':materialDrawer')

关于android - 无法解析 : project :Library:materialDrawer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46070588/

相关文章:

android - 初始化 Android(服务器)和 pc(客户端)上的 bluecove 之间的蓝牙连接

Android 谷歌地图 - 在标记上方显示线

android - 使用 AAR 和源 JAR 将 Android 库发布到 Maven

android release app bundle 构建缺少 native lib .so 文件

gradle - 动态创建的复制类型任务始终是最新的

android - 更新 Firebase Crashlytics SDK 时出现问题

java - 在 android studio 2.2.3 中未检测到 USB 设备或正在运行的模拟器

java - 取消异步任务

android-studio - gradle 二进制文件在 Android Studio 安装 (Linux) 上的位置

android - 如何解决错误 : In project 'app' a resolved Google Play services library dependency