为什么Android Studio无法识别.jar库导入? [英] Why does Android Studio don't recognize .jar library imports?

查看:184
本文介绍了为什么Android Studio无法识别.jar库导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Android Studio项目中使用一些.jar文件作为库。

I'm trying to use some .jar files as libraries in my Android Studio project.

我一直在寻找如何做到这一点,以及常规方法是复制libs文件夹中的.jar文件,然后将其添加为库。我知道libs文件夹必须位于项目视图中的app模块中。但是没有出现添加为库的选项。所以我的方法是手动添加它,右击app并:

I've been looking on how to do it, and the regular way is to copy the .jar file in the libs folder, and then add it as library. I know the libs folder must be inside "app" module in the "project" view. But that option to add as library doesn't appear. So my approach is to add it manually doing right click on "app" and:

打开模块设置/ app / Dependencies /并将.jar文件添加为文件依赖。

Open Module Setings/app/Dependencies/ and there add .jar files as file dependency.

然后,我转到我的.class,但导入建议不允许我选择这些库作为导入。

Then, I go to my .class but the import suggestions don't let me select these libraries as import.

我从android视图尝试了另一种方法。右键单击app并选择新模块,在那里我选择导入.JAR或.AAR包,然后从Open Module Setings中执行与之前相同的操作,但这次我添加它as 模块依赖性。

I have tried another approach from the "android" view. Doing right click on "app" and selecting "new module", there I select Import .JAR or .AAR Package and then I do the same as before from Open Module Setings, but this time I add it as Module Dependency.

在booth方式中,gradle.build文件会更新,添加这些依赖项,但在进入活动时选择导入,它没有让我有机会从这些导入中选择导入。

In booth ways, the gradle.build file is updated adding these dependencies, but when going to the activity to select the import, it doesn't give me the chance to select the import from these ones.

我花了整整一天试图解决这个问题,但我没有得到我的活动是识别从这些文件中导入的内容,所以如果有人能告诉我我做错了什么或者我不想做什么,我将不胜感激。

I have spent a full day trying to solve this, but I don't get my activity to recognize the imports from these files, so I would appreciate if someone could tell me what I'm doing wrong or what I'm missing to do.

Top -level build.gradle文件:

Top-level build.gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
         classpath 'com.android.tools.build:gradle:1.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

app-level build.gradle文件:

app-level build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/values-v14'] } }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
}

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


推荐答案

与MD聊天后,我们得出的结论是我的AS无法识别.jar文件,所以我不得不将项目移回到eclipse,它在那里工作正常。

After a chat with M D we arrived to the conclusion that my AS does not recognize the .jar files, so I have had to port the project back to eclipse, and it works fine there.

这篇关于为什么Android Studio无法识别.jar库导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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