gpt4 book ai didi

java - 如何将 EasyPost 库添加到 Android Studio 项目

转载 作者:行者123 更新时间:2023-11-30 10:52:03 24 4
gpt4 key购买 nike

我已经下载了库,它是一个包含多个文件的文件夹: https://github.com/EasyPost/easypost-java/archive/master.zip

我已经添加了我自己的名为 myLibs 的文件夹,并将解压缩的项目文件夹添加到其中(名为 easypost-java-master 的文件夹)。

我的 settings.gradle 如下所示:

include ':app'
include ':myLibs:easypost-java-master'

我的 build.gradle 如下所示:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')

compile fileTree(dir: 'myLibs', include: ['easypost-java-master'])
}

我没有收到任何错误并且能够同步。但是当我尝试导入例如 import com.easypost.EasyPost; 在我的 MainActivity 时,我得到了错误

无法解析 easypost

我错过了一步吗?

最佳答案

Am I missing a step?

是的,大的。在 EasyPost 库 GitHub 配置文件中,有安装说明。你注意到了吗:

Installation

mvn package or build the jar from src!

要做到这一点,只需按照以下步骤操作:

In the latest build of Android Studio 1.2, the creation of JAR library has been made as simple as point and click.

Steps to follow :

  • Goto File -> New -> New Module enter image description here
  • Select "Java Library" at the end of the options list enter image description here
  • Enter the name of the jar lib and name of class in it and hit finish button enter image description here
  • Thats it !

The next step is adding your Jar Library as dependency in your app. Simple as that just

  • Goto File -> Project Structure -> Select 'app' -> Select 'Dependency'
  • Select the '+' at the bottom -> Select 'Module Dependency' enter image description here
  • Select your jar lib module you just created above enter image description here enter image description here
  • Select Ok and thats it!

....Or you could just add the below line to your App gradle file

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) // Default Gradle Task, should be already present
compile 'com.android.support:appcompat-v7:21.0.3' // Default Gradle Task, should be already present

compile project(':nameOfYourJarLibraryModule') // This is your jar library module
}

Google is promoting the Android Archive(AAR), even though JAR supported is brought back to android studio.To find out the difference between AAR and JAR refer this link

From: Create an Android Jar library for distribution

希望对你有帮助

关于java - 如何将 EasyPost 库添加到 Android Studio 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34519448/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com