私は、Androidとデスクトップ(JavaSE)上で動作するプロジェクトに取り組んでいます。私は3つのJavaのモジュールにそれを分離しました。この目的のために:Androidスタジオ:JavaSEアプリケーション
- AndroidApp
- CommonCore
- DesktopApp
私は、Androidスタジオ(AS)を使用していますなぜ明らかです。 JavaSEモジュールの "実行"ボタンのほとんどは動作するようになっています。問題は単純です:不完全なクラスパス。モジュールはコンパイルされますが、実行されません。私がJARにビルドすると、うまく動作します。 JARには、必要なすべての依存関係が含まれています。唯一の問題は、JavaSEモジュールで使用するときに気をつけた "実行"ボタンです。
トップレベルのbuild.gradle:(かなりASによって生成される)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
CommonCoreのbuild.gradle:
apply plugin: 'java-library'
targetCompatibility="1.8"
sourceCompatibility="1.8"
dependencies {
api 'org.nanohttpd:nanohttpd:2.3.1'
api 'com.google.code.gson:gson:2.8.1'
api 'org.apache.commons:commons-text:1.1'
api files('src/main/resources')
}
DesktopAppのbuild.gradle:
apply plugin: 'java'
targetCompatibility="1.8"
sourceCompatibility="1.8"
dependencies {
implementation project(':CommonCore')
implementation 'org.xerial:sqlite-jdbc:3.21.0.1'
}
jar {
manifest {
attributes 'Main-Class': 'myproject.Main'
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
AndroidApp build.gradle :(実際のアンドロイドの設定を省略して、短くしておく)
私はそれを実行するとapply plugin: 'com.android.application'
dependencies {
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation project(':CommonCore')
}
android { ... }
私が取得:
Exception in thread "main" java.lang.NoClassDefFoundError: fi/iki/elonen/NanoHTTPD
どうやらJVMが依存 'org.nanohttpd:nanohttpd:2.3.1' が見つかりませんでしたCommonCoreからを。クラスパスを調べた後、私は参照してください:
/Applications/Android Studio.app/Contents/jre/jdk/<a ton of unused JARs>
/Users/bamboo/AndroidStudioProjects/MyProject/DesktopApp/build/classes/java/main
/Users/bamboo/AndroidStudioProjects/MyProject/CommonCore/build/classes/java/main
Gradleによって管理される依存関係のエントリがありません。
どうしたのですか?オートコンプリートがうまく機能するため、ASはそれらを表示する必要があります。 Gradleの中runtime()
内部
コンパイル時にlibが見つからないためコンパイルされません –