java - Android工作室: How to source android jar in a module

标签 java android android-studio

我刚刚从 eclipse 切换到 android studio(因为 FB SDK),所以这可能是一个愚蠢的问题。在我的 android 项目中,我创建了一个名为 dbUtils 的模块(Java 库),我在其中使用 greenDAO 将数据保存在 SQLite 中。它需要导入

import android.content.Context;

找不到这个类。我无法弄清楚我需要添加什么依赖项。在 :app 模块下,这是可以识别的。

最佳答案

您应该在 build.gradle 文件中使用 android-library 插件。看看here 。这样Android Studio就会知道这个项目是一个android库(而不仅仅是一个java库)并导入所需的类。我已经使用过并且有效。这是我的 build.gradle 文件

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(':validationutils')
}

关于java - Android工作室: How to source android jar in a module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29503906/

相关文章:

android - 低功耗蓝牙 (BTLE) 设备支持

android - 除了UIAutomator 2.0版本名称,UIObject和UIObject2之间有什么区别?

java - KeyListener 有问题

java - 部署时出现 GAE 端点错误 500

java - Google Play 登录始终失败异常 : 4

我的应用程序的 Android APK 下载不起作用,Xamarin.Android

用于 ORMLite 配置生成的 Android Studio 运行配置

android - 是否可以在 Android Studio 中本地调试 Google Play 的应用内计费?

android - Android Studio为每个项目下载不同等级

java - 最好的选择。在 Java 应用程序中使用 .Net Dll