我一直在尝试按照此问题中提供的指南在我的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'
答案 0 :(得分:5)
获取AAR port of the library(v1.3)。
GitHub页面已关闭,因此您必须手动导入that AAR:
热门 build.gradle 文件:
repositories {
flatDir {
dirs 'libs'
}
}
将AAR文件放在模块的 libs 文件夹中,然后放在模块 build.gradle 文件中:
dependencies {
compile(name:'library-1.3', ext:'aar')
}