简体   繁体   English

如何将jar文件(Maven)导入Android Studio?

[英]How to import jar file (maven) into Android Studio?

I want to import a jar file into my Android project.( here is the jar file ) 我想将jar文件导入我的Android项目。( 这是jar文件
Here are my steps: 这是我的步骤:

  1. Add two lines (Class-Path and Main-Class) in MANIFEST.MF file 在MANIFEST.MF文件中添加两行(类路径和主类)
    Class-Path: libs/nineoldandroids-2.4.0.jar 类路径:libs / nineoldandroids-2.4.0.jar
    Main-Class:com.demos.tencent_qq_ui.Aty.MainActivity 主类:com.demos.tencent_qq_ui.Aty.MainActivity

  2. Drag the jar file in the directory libs 将jar文件拖到目录libs中

  3. Right click "Add as Library" 右键单击“添加为库”

  4. Edit my build.gradle file 编辑我的build.gradle文件
    dependencies { 依赖项{
    compile fileTree(dir: 'libs', include: ['*.jar']) 编译fileTree(dir:'libs',包括:['* .jar'])
    compile 'com.android.support:appcompat-v7:22.2.0' 编译'com.android.support:appcompat-v7:22.2.0'
    compile files('libs/nineoldandroids-2.4.0.jar') 编译文件('libs / nineoldandroids-2.4.0.jar')
    } }

Rebuild Project --> Run 重建项目->运行

But it occured an error : Couldn't find or load Main Class com.demos.tencent_qq_ui.Aty.MainActivity 但是它发生了一个错误: 无法找到或加载Main类com.demos.tencent_qq_ui.Aty.MainActivity

I google it for a long time,but didn't get much useful info ... 我用谷歌搜索了很长时间,但没有得到很多有用的信息...

Any help in catching my mistake would be greatly appreciated.Thank you! 任何帮助我发现错误的方法将不胜感激。谢谢!
OS: ubuntu 15.04 作业系统:ubuntu 15.04
IDE:Android Studio 1.2 IDE:Android Studio 1.2

<dependency>
  <groupId>com.nineoldandroids</groupId>
  <artifactId>library</artifactId>
  <version>2.4.0</version>
</dependency>

I guess this could be transformed to gradle dependency like this: 我猜这可以转换为gradle依赖这样的:

dependencies {
  compile 'com.nineoldandroids:library:2.4.0'
}

As the library is on maven central this should work. 由于该库位于Maven中央,因此应该可以使用。 I don't think you need to add anything to your MANIFEST.MF 我认为您不需要在MANIFEST.MF中添加任何内容

Make sure you have mavenCentral in your build.gradle like this: 确保在build.gradle中具有如下所示的mavenCentral:

buildscript {
    repositories {
        mavenCentral()
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM