Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle error with Android project added as a library (SlidingMenu) [package does not exist]

I've never used Gradle before so I'm completely lost!

I've added SlidingMenu as a library and I have access from my project to all the SlindingMenu stuff, but trying to compile will give me this error:

Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist

I'm using Android Studio (so IntelliJ) and this is my gradle.build

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'
dependencies {
    compile files('libs/android-support-v4.jar')
}
android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }
}

Thanks in advance

like image 202
Enrichman Avatar asked May 20 '13 13:05

Enrichman


2 Answers

Assuming you have added SlidingMenu.jar into libs folder, right click on it -> Add as library. Then change in gradle.build:

Before:

dependencies {
    compile files('libs/android-support-v4.jar')
}

After:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

This will include all your jar files.

like image 73
leadrien Avatar answered Oct 18 '22 21:10

leadrien


I had the same problem. Adding sliding-menu-lib from with gradle-build as android library did help me.

My project structure is as:

-MyDemoProject
-build.gradle
-settings.gradle
--MyDemo
--build.gradle
--libs
---sliding-menu-lib
----res
----src
----AndroidManifest.xml
----build.gradle
--src

To make all the stuff working your settings.bundle should have this contents:

include ':MyDemo' ':MyDemo:libs:sliding-menu-lib'

There is a trick here, which allows you avoid errors while building project with gradle using Android Studio, as according to Android Tools Manual you should use ':libs:sliding-menu-lib' but that does not work due to issue with relative projectDir paths.

Your MyDemo/build.gradle should contain dependencies like:

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    ...
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':MyDemo:libs:sliding-menu-lib')

}

And your sliding-menu-lib/build.gradle should be like:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 14
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 14
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

Most important part deals with sourceSets section as you may not want change sliding-menu-lib file structure (non-default for current gradle)

like image 41
Sergii N. Avatar answered Oct 18 '22 20:10

Sergii N.