Adding Library Source into Android Studio

2019-01-25 22:10发布

I am sorry fr asking this newbie question.

I am trying to use this library i my project. https://github.com/gfranks/GFMinimalNotifications

I would like to import the source codes and not the binary.

The github page says Simply copy the source/resource files from the library folder into your project.

So I tried to drag and drop these two files directly to my libs folder in Android Studio.

And I went back to my Activity and try to use it in my code. But the autocomplete does not seem to recognize the library.

Any help please? After I copied into my libs folder.

Importing the whole module seems to be wasteful considering the project has many assets that is irrelevant to the library itself.

Found the solution

I copied it to the app/libs folder, and then in build.gradle I add

sourceSets {
    main.java.srcDirs += 'libs/GFMinimalNotifications/src/main/java'
}

4条回答
三岁会撩人
2楼-- · 2019-01-25 22:17

there is two way to use this we ll use 2nd method Use binary approach

  1. Copy com.github.gfranks.minimal.notification-1.0.aar into your projects libs/ directory.

  2. Include the following either in your top level build.gradle file or your module specific one:

    repositories { flatDir { dirs 'libs' } }

  3. Under your dependencies for your main module's build.gradle file, you can reference that aar file like so: compile 'com.github.gfranks.minimal.notification:com.github.gfranks.minimal.notification-1.0@aar'


after do above step try to sync gradle if there is issue like

Suggestion: use tools:overrideLibrary="com.github.gfranks.minimal.notification" to force usage

then add below code in android manifest file

add below line in side manifest TAG

xmlns:tools="http://schemas.android.com/tools"

add below line above Application TAG

<uses-sdk
        tools:overrideLibrary="com.github.gfranks.minimal.notification"/>

finally your manifest look like

<?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>
查看更多
可以哭但决不认输i
3楼-- · 2019-01-25 22:22

Simple step

  1. Download full project from git and extract.
  2. In android studio File -> New -> Import Module -> Browse directory you extract project.
  3. Resync Gradle.
查看更多
The star\"
4楼-- · 2019-01-25 22:36

copy in project full package library

in settings gradle add include ':library',':app'

in build.gradle

dependencies {
    ...
    compile project(':library')
}

enter image description here

查看更多
不美不萌又怎样
5楼-- · 2019-01-25 22:38

Steps to add modules in Android Studio download zip file & follow steps

Follow Step first

Step second Step third Step fourth

查看更多
登录 后发表回答