Android Studio:添加作为库选项缺失。

19
我开始使用Android Studio时遇到了一个问题。当我在项目中添加库时,我找不到“Add as Library”选项。以下是我添加库的步骤:
* 在app存储库中的libs文件夹中添加库。
* 右键单击以查看“Add as Library”选项。(无法看到!)
* 由于上述步骤不起作用,我考虑直接在资源管理器中的libs文件夹中添加库。失败了!
因此,我无法继续进行我的项目。
P.S .:我已经删除了Eclipse,并且不想再安装和设置它。
build.gradle文件:
apply plugin: 'com.android.application'

android {
          compileSdkVersion 21
          buildToolsVersion "21.1.2"

          defaultConfig {
                         applicationId "com.example.team1cloud.cloudapp"
                         minSdkVersion 15
                         targetSdkVersion 21
                         versionCode 1
                         versionName "1.0"
                        }
buildTypes {
    release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
          }
        }
dependencies
      {
       compile fileTree(dir: 'libs', include: ['*.jar'])
       compile 'com.android.support:appcompat-v7:21.0.3'
       compile 'com.google.apis:google-api-services-drive:v2-rev161-1.19.1'
       compile files('libs/commons-logging-1.1.1.jar')
       compile files('libs/google-api-client-1.18.0-rc.jar')
       compile files('libs/google-api-client-android-1.18.0-rc.jar')
       compile files('libs/google-api-client-appengine-1.18.0-rc.jar')
       compile files('libs/google-api-client-gson-1.18.0-rc.jar')
       compile files('libs/google-api-client-jackson2-1.18.0-rc.jar')
       compile files('libs/google-api-client-java6-1.18.0-rc.jar')
       compile files('libs/google-api-client-protobuf-1.18.0-rc.jar')
       compile files('libs/google-api-client-servlet-1.18.0-rc.jar')
       compile files('libs/google-api-client-xml-1.18.0-rc.jar')
       compile files('libs/google-http-client-1.18.0-rc.jar')
       compile files('libs/google-http-client-android-1.18.0-rc.jar')
       compile files('libs/google-http-client-appengine-1.18.0-rc.jar')
       compile files('libs/google-oauth-client-java6-1.18.0-rc.jar')
       compile files('libs/google-oauth-client-jetty-1.18.0-rc.jar')
       compile files('libs/google-oauth-client-servlet-1.18.0-rc.jar')
       compile files('libs/google-play-services.jar')
       compile files('libs/gson-2.1.jar')
       compile files('libs/httpclient-4.0.1.jar')
       compile files('libs/httpcore-4.0.1.jar')
       compile files('libs/jackson-core-2.1.3.jar')
       compile files('libs/jackson-core-asl-1.9.11.jar')
       compile files('libs/jdo2-api-2.3-eb.jar')
       compile files('libs/jetty-6.1.26.jar')
       compile files('libs/jetty-util-6.1.26.jar')
       compile files('C:/Users/sjeet/AndroidStudioProjects/CloudApp/gradle/wrapper/gradle-wrapper.jar')
     }

谢谢。 请帮帮忙!!!


请发布您的Gradle文件。 - IshRoid
2个回答

3

Android Studio是基于gradle的。如果您的项目有一个jar文件作为依赖项,打开build.gradle文件并在依赖项部分添加。

 compile files('libs/name_file.jar')

如果将库的源代码作为依赖项导入,您可以使用:

compile project(':NameProject')

编译它。

您应该能够通过UI执行相同的操作。

右键单击项目,然后单击打开模块设置,然后单击依赖项选项卡。从那里,您可以将jar或库项目添加为主项目的依赖项。


我正在使用GoogleDrive API创建一个项目。我添加了GoogleApiClient库,并且在build.gradle中也添加了以下内容: compile files('libs/google-api-client-1.18.0-rc.jar') 但它不起作用。 - user2607744
你又同步了吗? - Blackbelt
我如何理解库 google-api-client-1.18.0-rc.jar 是一个库、文件还是模块依赖?是的,我已经尝试了3个小时! - user2607744

0

我又浪费了一天的时间,按照上述建议却毫无成果。然后我所做的是...

  1. 关闭我的项目
  2. 关闭 Android Studio
  3. 使用 Windows 10 直接将一个 jar 文件从另一个位置复制到 MyProject/app/libs 文件夹
  4. 启动 Android Studio,打开我的项目并等待同步完成,确保在项目视图而不是 Android 视图中
  5. 该 jar 文件出现在 libs 文件夹中 就像魔术一样,
  6. 当我右键单击 jar 文件时,"添加为库" 出现在列表底部附近。点击它,从此幸福快乐地生活着 :) 证毕

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接