How to Import Github non Android Studio Project as

2019-08-31 12:01发布

问题:

I am trying to import standout library which is a github project as library in my project.What i tried is below:

  • created a folder in my root project directory named 'libs'

    • copied the complete folder 'library' of the Standout project on git into 'libs'
    • renamed the folder 'library' that i just copied to e.g. "standout" (just to avoid confusion)
    • now added this library in my settings.gradle with the following command:

      include ':libs:standout'

    • going to my build.gradle file of my AppProject and added the following line to my 'dependencies':

      compile project(':libs:standout')

    • but i got error and then added like this

       compile fileTree(dir: 'libs', include: ['standout'])
      

gradle sync was successful but there is red mark on the src files of the library project..
I couldn't access the library src files from MainActivity of my Project.As the github project wasn't the android studio project do i need to do anything extra for that?

I have tried below way suggested by Wesley:

Download or clone the git repository, copy the library folder into your project root folder.

Then in your project settings.gradle file, add a ':library' at the end of the include line, like this: include ':app', ':library', then gradle sync your whole project.

At the end, in your app module or you own application module, edit the build.gradle file, add a line in your dependencies:

compile project(':library')

BTW, you can change the folder name ("library" in this case) to any name you want (like "standout-library" if you want) when copy it into you project's root folder, then, when you edit the gradle files, just use the changed name.

But got the below error:

Error:Configuration with name 'default' not found.

My build.gradle:

  apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.mapandmap.standout"
        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 project(':standout')
    compile 'com.android.support:appcompat-v7:22.1.1'

}

My settings.gradle:

include ':app',':standout'

screenshot of my Project Tree:

回答1:

You need to resolve R in each file of "standout" library which is showing as red now. You can simply add by doing this. Go to Android Studio File->Project Structure-> + , You will get four options to add a new module. From there choose "Import Existing Project"->Next-> browse to the directory you have downloaded library and choose "library" directory and then "Finish".Android Studio will take some time to sync library to your project. Finally add dependency in settings. I just tested by adding this library in a project and its working perfectly. You could move the library to your main "app" project but its better to add as dependency.



回答2:

I followed the answer of sbr1308 but I have to do some more things.What you have to do:

  • Go to Android Studio File->Project Structure-> + , You will get four options to add a new module. From there choose "Import Existing Project"->Next-> browse to the directory you have downloaded library and choose "library" directory and then "Finish"
  • If there is any error in the classes of the library then Go to File->Invalidate Caches/Restart->Invalidate and Restart.It will take time to indexing.
  • You have to add the dependency in the app's build.gradle compile project(':standOut') and then sync.