我一直在尝试按照此问题中提供的指南在我的 Android Studio 项目中使用 SlidingMenu 库:

How to import slidingmenu on Android Studio?

我已经能够获得描述的文件结构并同步和构建项目而没有错误。然而,当尝试将滑动菜单导入我的应用程序源文件时,我收到了符号解析错误。

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; // Error message: Cannot resolve symbol 'SlidingMenu'
import com.jeremyfeinstein.slidingmenu.lib.BuildConfig;

第二个导入是 Android Studio 唯一建议的导入,但在遵循给定路径时,我什至无法在我的项目中找到 BuildConfig 文件。

我需要更改什么才能将 com.jeremyfeinstein.slidingmenu.lib 中的所有类导入到我自己的类中?

我的应用程序 gradle 文件如下所示:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.0.0'
    compile project(':libraries:SlidingMenu')
}

SlidingMenu gradle 文件:
buildscript {
    // define the repo which is to use
    repositories {
        mavenCentral()
    }
    // define the classpath for Gradle Android Plugin
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.+'
    }
}

// declaring that the project is a library
apply plugin: 'android-library'

// declaring all dependencies the project needs
dependencies {
    compile 'com.android.support:support-v4:19.0.0'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        // this values you can read out from the Manifest (but I add the right values for you)
        minSdkVersion 17
        targetSdkVersion 21
    }

    // because Android Studio has a different file structure than Eclipse
    // you have to say Android Studio where the files are located
    sourceSets{
        main{
            java.srcDirs = ['src/main/java']
            res.srcDirs = ['src/main/res']

            manifest.srcFile 'AndroidManifest.xml'
        }
    }
}

项目设置gradle:
include ":libraries:SlidingMenu", ':app'

最佳答案

获取 AAR port of the library (v1.3)。

GitHub Pages 已关闭,因此您必须手动导入 that AAR:

顶部 build.gradle 文件:

repositories {
    flatDir {
        dirs 'libs'
    }
}

将 AAR 文件放在模块的 libs 文件夹中,然后放在模块 build.gradle 文件中:
dependencies {
    compile(name:'library-1.3', ext:'aar')
}

10-08 19:07