库无法解析R.符号

时间:2015-05-16 05:14:14

标签: java android gradle

我尝试添加外部库“ ViewPagerIndicator ”。

我将build.gradle添加到库并进行编译。 库中有一些类无法导入支持库,但我在我的应用程序的build.gradle中有它

import android.support.v4.view.MotionEventCompat;

它给了我Error:(28, 31) error: package android.support.v4.view does not exist。图书馆无法解析R.符号。

然后我尝试在ViewPagerIndicator库中添加支持库

以下是Application/ViewPagerIndicator/build.gradle

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:support-v4:22.1.1'
}
apply plugin: 'com.android.library'  //Tells the build this is a library project

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'  //Where to find specific parts of the project
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        instrumentTest.setRoot('tests')
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

它给了我Gradle DSL method not found 'compile()'错误。

请说,如何解决它

更新

我将dependencies放在android下方。

apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'com.android.library'  //Tells the build this is a library project

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 22
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'  //Where to find specific parts of the project
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}
configurations {
    // Used for correct javadoc generation
    javadoc.extendsFrom compile
}
dependencies {
     compile fileTree(include: ['*.jar'], dir: 'libs')
     compile 'com.android.support:appcompat-v7:22.1.1'
     compile 'com.android.support:support-v4:22.1.1'
}

它有效,但根本没有

图书馆仍然无法解析R.符号

0 个答案:

没有答案