Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio can't find library classes after Gradle build

I'm trying to add a .jar library to my project into the /libs folder. Here is my grade.build:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4'
        }
    }
    apply plugin: 'android'

    dependencies {
        compile files('libs/android-support-v4.jar', 'libs/java-api-wrapper-1.2.0-all.jar')
    }

    android {
        compileSdkVersion 17
        buildToolsVersion "17.0.0"

        defaultConfig {
            minSdkVersion 15
            targetSdkVersion 16
        }
    }

After I add that, I build my project and there are no errors. But when I try to use the class in my code private ApiWrapper wrapper, I get an error:

Gradle: error: cannot find symbol class ApiWrapper

I can't quite find where the error is. Is my grade.build not ok, or am I supposed to build it some other way?

like image 996
tolgap Avatar asked Jun 02 '13 12:06

tolgap


People also ask

Where do I put libraries in Android Studio?

Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Library Dependency in the dropdown. In the Add Library Dependency dialog, use the search box to find the library to add.


2 Answers

Using the command line, in the root of your project, run :
./gradlew clean && ./gradlew build

Then recompile your project in studio and you should see your new lib.

like image 83
lukas Avatar answered Oct 27 '22 09:10

lukas


Set minifyEnabled to false for all your library projects in build.gradle. See accepted answer by Scott Barta in this thread.

See accepted answer by Scott Barta in this thread

like image 43
Vinay Avatar answered Oct 27 '22 11:10

Vinay