android - 如何在我的 gradle 项目中添加 JAR?

标签 android gradle android-studio testflight android-gradle-plugin

我在 Android studio 中使用 gradle 进行 android 项目。我下载了一个名为 TestFlightAppLib.jar 的 jar。这个 jar 不在 Maven 存储库中,所以我不能将它放在我的 build.gradle 中。

如何将这个 JAR 文件添加到我的项目中?我看不到任何向项目添加外部 jar 的选项。

enter image description here

更新

这是我完整的build.gradle

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

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 18
    }

}

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.squareup.retrofit:retrofit:1.2.2'
    compile 'com.github.rtyley:roboguice-sherlock:1.5'
    compile 'org.roboguice:roboguice:2.0'
    compile files('libs/TestFlightLib.jar')
}

这是错误信息:

Gradle: Execution failed for task ':MyProject:compileDebug'.
> Compilation failed; see the compiler error output for details.
/Users/droid/android/MyProjectProject/MyProject/src/main/java/com/mypkg/ui/activity/MainApplication.java
Gradle: error: package com.testflightapp.lib does not exist

这是类:

import com.testflightapp.lib.TestFlight;


public class MainApplication  {

}

最佳答案

只需添加

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

build.gradle 中的 dependencies 然后 libs 文件夹中的所有 jar 都将被包含。

关于android - 如何在我的 gradle 项目中添加 JAR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21046095/

相关文章:

java - 通过签名报告运行 Android 应用程序时出错

java - LibGDX设置加速错误

java - ToggleButton 能否更改同一 Activity 中其他按钮的功能?

android - 使用Koin库时无法导入ViewModel

java - 反馈电子邮件android中的设备信息

android - 无法解决依赖android studio

java - KSOAP 解析错误 :- java. lang.ClassCastException : org. ksoap2.SoapFault

android - meteor 运行android设备错误

android - 在 Android Studio 中的 EditText 的所有四个边上放置阴影

java - 如何在一定时间后继续 for 循环而不使用 `try ... catch` 方法?