Gradle构建后Android Studio找不到库类 [英] Android Studio can't find library classes after Gradle build

查看:40
本文介绍了Gradle构建后Android Studio找不到库类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 .jar 库添加到我的项目的 /libs 文件夹中.这是我的 grade.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
        }
    }

添加后,我构建了我的项目并且没有错误.但是当我尝试在我的代码 private ApiWrapper wrapper 中使用该类时,出现错误:

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

我无法完全找到错误所在.我的 grade.build 不好吗,还是我应该以其他方式构建它?

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?

推荐答案

使用命令行,在项目的根目录中,运行:
./gradlew 清洁 &&./gradlew 构建

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

然后在 Studio 中重新编译您的项目,您应该会看到您的新库.

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

这篇关于Gradle构建后Android Studio找不到库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆