-1

I use Android Studio 2.2 and Gradle in offline mode. The value of Gradle Home is /path/to/gradle/gradle-2.14.1. I can run Android project but now I want to run a Java standard class to test some Java code before using them in Android project. So I followed this answer. But when I run class, I got an error like this:

Error:Gradle: A problem occurred configuring root project 'demo'.
 > Could not resolve all dependencies for configuration ':classpath'.
 > Could not resolve com.android.tools.build:gradle:2.2.2.
 Required by:
     :demo:unspecified
  > No cached version of com.android.tools.build:gradle:2.2.2 available for  offline mode.

Also here is content of build.gradle of Java library:

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

How I can solve this problem? (I do not want to use another IDE or enabling online mode for Gradle)

Community
  • 1
  • 1
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167

1 Answers1

3

You have to download com.android.tools.build:gradle:2.2.2...

And that requires internet. The package gradle-2.14.1 is not the same thing, as that is Gradle itself, and not the Android Gradle plugin.

Though, it is not clear why you have applied that plugin on a standard Java module.

All you need is

apply plugin: 'java'

In other words, Gradle simply builds Android code. It's not related to Android in anyway other than that, and you can run Java projects independent of Android if you set it up correctly.

Gradle - Java Plugin


For example,

java-code/build.gradle

apply plugin: 'java'

targetCompatibility = '1.7'
sourceCompatibility = '1.7'

test {
    testLogging {
        // Show that tests are run in the command-line output
        events 'passed'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
}

app/build.gradle

apply plugin: 'com.android.application'
evaluationDependsOn(':java-code')

...

dependencies {
    compile project(":java-code")
    compile fileTree(dir: 'libs', include: ['*.jar'])

    ...
}

settings.gradle

include ':app', ':java-code'
Community
  • 1
  • 1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245