尝试导入picasso库时出错

时间:2016-09-05 16:04:19

标签: android gradle build.gradle

我想将picasso库导入我的android工作室,但是当我尝试这个时。 Android工作室给我一个消息:

错误:(3,0)无法在org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@71d5a575上找到属性'dep'。 打开文件

那么如何解决呢?我真的需要你的帮助。 这是我的应用程序:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

另一个:

  apply plugin: 'com.android.application'

  android {
compileSdkVersion 23
buildToolsVersion "23.0.0"

defaultConfig {
    applicationId "com.example.hp.refomandaapps"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

  dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile project(":lib-release")
   compile project(":circleindicator-debug")
   compile 'com.android.support:appcompat-v7:23.4.0'
   compile 'com.google.android.gms:play-services:9.0.2'
   compile 'com.android.support:support-v4:23.4.0'
   compile 'com.squareup.picasso:picasso:2.5.2'

   }

2 个答案:

答案 0 :(得分:0)

以下是我的示例build.gradle文件。请注意,有两个build.gradle文件,一个位于app文件夹下,另一个位于项目文件夹下。

App 文件夹下的那个看起来像这个

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "app.com.example.android.appname"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral ()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
}

我发现您的gradle文件中没有存储库标记。尝试添加它,看看是否能解决问题。 项目文件夹下的那个看起来像这样

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

也可能是不同的库发生冲突,您必须启用多索引。有关详细信息,请参阅此帖子 Runtime Error When Adding Picasso to Gradle 让我知道这个是否奏效。祝你好运!

答案 1 :(得分:0)

尝试使用multidex这可能会解决您的问题

Module.gradle

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>
相关问题