我怎么能在我的摇篮项目中添加一个JAR? [英] How can I add a JAR in my gradle project?

查看:119
本文介绍了我怎么能在我的摇篮项目中添加一个JAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的摇篮在Android的工作室为Android项目。我有一个我下载一个名为 TestFlightAppLib.jar 罐子。这罐子是不是present在Maven仓库,所以我不能只是把它放在我的 build.gradle

我怎么能这个JAR文件添加到我的项目?我没有看到任何选项外部jar添加到项目中。

更新

这是我的完整build.gradle

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径com.android.tools.build:gradle:0.6.+
    }
}
应用插件:'机器人'

库{
    mavenCentral()
}

安卓{
    compileSdkVersion 18
    buildToolsVersion18.1.1

    defaultConfig {
        的minSdkVersion 8
        targetSdkVersion 18
    }

}

依赖{
    编译com.actionbarsherlock:actionbarsherlock:4.4.0@aar
    编译com.android.support:support-v4:18.0.+
    编译com.google code.gson:GSON:2.2.4
    编译com.squareup.retrofit:改造:1.2.2
    编译com.github.rtyley:roboguice-福尔摩斯:1.5
    编译org.roboguice:roboguice:2.0
    编译文件(库/ TestFlightLib.jar)
}
 

这是错误消息:

 摇篮:执行失败的任务:MyProject的:compileDebug。
>编译失败;详见编译器错误输出。
/Users/droid/android/MyProjectProject/MyProject/src/main/java/com/mypkg/ui/activity/MainApplication.java
摇篮:错误:包com.testflightapp.lib不存在
 

下面是类:

 进口com.testflightapp.lib.TestFlight;


公共类MainApplication {

}
 

解决方案

只是添加

 编译文件树(导演:库,包括:的* .jar)
 

你的依赖 build.gradle 然后在库文件夹中所有的jar文件将被包括在内。

I am using gradle in Android studio for an android project. I have a jar that I downloaded called TestFlightAppLib.jar. This jar isn't present in the maven repository so I can't just put it in my build.gradle.

How can I add this JAR file to my project? I don't see any option to add an external jar to the project.

Update

This is my complete 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')
}

This is the error message:

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

Here is the class:

import com.testflightapp.lib.TestFlight;


public class MainApplication  {

}

解决方案

just add

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

to your dependencies in the build.gradle then all the jars in the libs folder will be included.

这篇关于我怎么能在我的摇篮项目中添加一个JAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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