簡體   English   中英

使用離線Gradle運行標准Java項目時出現Android Studio錯誤

[英]Android Studio error on running standard java project with offline gradle

我在離線模式下使用Android Studio 2.2Gradle Gradle Home值為/path/to/gradle/gradle-2.14.1 我可以運行Android項目,但現在我想運行Java標准類來測試一些Java代碼,然后再在Android項目中使用它們。 所以我遵循了這個答案 但是當我運行課程時,出現了如下錯誤:

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.

這也是Java庫的build.gradle的內容:

apply plugin: 'java'

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

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

我該如何解決這個問題? (我不想使用其他IDE或為Gradle啟用在線模式)

您必須下載com.android.tools.build:gradle:2.2.2 ...

這需要互聯網。 軟件包gradle-2.14.1是不同的東西,因為它是Gradle本身,而不是Android Gradle插件

不過,目前尚不清楚為什么在標准Java模塊上應用了該插件。

所有你需要的是

apply plugin: 'java'

換句話說,Gradle只是構建Android代碼。 除此之外,它與Android都不相關,如果正確設置了Java項目,則可以獨立於Android運行Java項目。

Gradle-Java插件


例如,

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'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM