将库源添加到 Android Studio
Adding Library Source into Android Studio
很抱歉问了这个新手问题。
我正在尝试在我的项目中使用这个库:
https://github.com/gfranks/GFMinimalNotifications
我想导入源代码而不是二进制文件。
github 页面显示 Simply copy the source/resource files from the library folder into your project.
所以我尝试将这些 two files 直接拖放到 Android Studio 中我的 libs
文件夹中。
然后我回到 Activity 并尝试在我的代码中使用它。但是自动完成似乎无法识别该库。
有什么帮助吗?
在我复制到我的 libs 文件夹后。
考虑到项目中有许多与库本身无关的资产,导入整个模块似乎很浪费。
找到解决方案
我把它复制到app/libs
文件夹,然后在build.gradle
我添加
sourceSets {
main.java.srcDirs += 'libs/GFMinimalNotifications/src/main/java'
}
简单步骤
- 从 git 下载完整项目并解压缩。
- 在 android studio File -> New -> Import Module -> Browse directory 你提取项目。
- 重新同步 Gradle。
在 Android Studio 中添加模块的步骤
下载 zip 文件并按照步骤操作
在项目完整包中复制library
在设置中 gradle 添加 include ':library',':app'
在 build.gradle
dependencies {
...
compile project(':library')
}
有两种使用方法,我们将使用第二种方法使用二进制方法
将com.github.gfranks.minimal.notification-1.0.aar复制到您的项目libs/目录中。
在顶级 build.gradle 文件或模块特定文件中包含以下内容:
存储库{
flatDir {
目录 'libs'
}
}
在主模块 build.gradle 文件的依赖项下,您可以像这样引用该 aar 文件:compile 'com.github.gfranks.minimal.notification:com.github.gfranks.minimal.notification-1.0@aar'
完成上述步骤后尝试同步 gradle
如果有类似
的问题
Suggestion: use tools:overrideLibrary="com.github.gfranks.minimal.notification" to force usage
然后在 android 清单文件中添加以下代码
在侧面清单 TAG 中添加以下行
xmlns:tools="http://schemas.android.com/tools"
在应用程序标签上方添加下面一行
<uses-sdk
tools:overrideLibrary="com.github.gfranks.minimal.notification"/>
最后你的清单看起来像
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.test" >
<uses-sdk
tools:overrideLibrary="com.github.gfranks.minimal.notification"/>
<application... >your all code </application></manifest>
很抱歉问了这个新手问题。
我正在尝试在我的项目中使用这个库: https://github.com/gfranks/GFMinimalNotifications
我想导入源代码而不是二进制文件。
github 页面显示 Simply copy the source/resource files from the library folder into your project.
所以我尝试将这些 two files 直接拖放到 Android Studio 中我的 libs
文件夹中。
然后我回到 Activity 并尝试在我的代码中使用它。但是自动完成似乎无法识别该库。
有什么帮助吗? 在我复制到我的 libs 文件夹后。
考虑到项目中有许多与库本身无关的资产,导入整个模块似乎很浪费。
找到解决方案
我把它复制到app/libs
文件夹,然后在build.gradle
我添加
sourceSets {
main.java.srcDirs += 'libs/GFMinimalNotifications/src/main/java'
}
简单步骤
- 从 git 下载完整项目并解压缩。
- 在 android studio File -> New -> Import Module -> Browse directory 你提取项目。
- 重新同步 Gradle。
在 Android Studio 中添加模块的步骤 下载 zip 文件并按照步骤操作
在项目完整包中复制library
在设置中 gradle 添加 include ':library',':app'
在 build.gradle
dependencies {
...
compile project(':library')
}
有两种使用方法,我们将使用第二种方法使用二进制方法
将com.github.gfranks.minimal.notification-1.0.aar复制到您的项目libs/目录中。
在顶级 build.gradle 文件或模块特定文件中包含以下内容:
存储库{ flatDir { 目录 'libs' } }
在主模块 build.gradle 文件的依赖项下,您可以像这样引用该 aar 文件:
compile 'com.github.gfranks.minimal.notification:com.github.gfranks.minimal.notification-1.0@aar'
完成上述步骤后尝试同步 gradle 如果有类似
的问题Suggestion: use tools:overrideLibrary="com.github.gfranks.minimal.notification" to force usage
然后在 android 清单文件中添加以下代码
在侧面清单 TAG 中添加以下行
xmlns:tools="http://schemas.android.com/tools"
在应用程序标签上方添加下面一行
<uses-sdk
tools:overrideLibrary="com.github.gfranks.minimal.notification"/>
最后你的清单看起来像
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.test" >
<uses-sdk
tools:overrideLibrary="com.github.gfranks.minimal.notification"/>
<application... >your all code </application></manifest>