-->

importing ShowcaseView with gradle

2019-05-18 09:52发布

问题:

I'm trying to use the ShowcaseView project in my app but can't get the project to build.

when I run 'gradle clean installDebug' I get the following error:

A problem occurred evaluating root project 'hows-it-going'.

Could not find method compile() for arguments [project ':ShowcaseView'] on root project 'hows-it-going'.

I'm using gradle 1.11 and Android Studio 0.54.

I've downloaded the source, and imported the project using file -> Import module -> ShowcaseView
which makes my project structure like:

-project
--app
--ShowcaseView

my settings.gradle file looks like:

include ':app', 'ShowcaseView'


and in my project level build.gradle I have the following:

dependencies {
  compile project (':ShowcaseView')
}

Any help with how to include this properly would be much appreciated. Thanks.

回答1:

I recently just added ShowcaseView to an Android Studio project, and I hope this can push you in the correct direction.

My file structure looks something like this:

  • project
    • app
      • build.gradle
    • libraries
      • showcase
    • build.gradle
    • settings.gradle

  1. Add the files from the library folder of ShowcaseView to the showcase directory in the libraries directory.

  2. Add the showcase directory as a module to your project.

  3. Change your app's build.gradle file to include:

    dependencies {
      compile project(':libraries:showcase')
    }
    
  4. Change your settings.gradle to include:

    include ':libraries:showcase'

  5. Sync Project with gradle files

This StackOverflow answer goes over how to do this is much more detail if you have any troubles, but this method works for any library.



回答2:

The latest version of ShowcaseView is available as a .AAR dependency. To use it, add:

repositories {
    mavenCentral()
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots'
    }
}

To your build.gradle file and, under the dependencies block, add:

compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT'

I'll get a stable, non-snapshot, version out soon.



回答3:

It should actually be

compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT@aar'

That way Maven will use .AAR file



回答4:

The compile dependency on ShowcaseView should likely be defined in app/build.gradle, not in the root project's build.gradle. Unless a project explicitly (configurations block) or implicitly (by applying a plugin such as java) defines a compile configuration, it won't have one, and an attempt to add a compile dependency will result in the error you mentioned.



回答5:

I added this in build.gradle and it worked

compile 'com.github.amlcurran.showcaseview:library:5.4.3'