グラデルビルドを使用してIntelliJ IDEAプロジェクトをAndroidスタジオに移行する際に問題があります。私はAndroidAnnotationsライブラリをさまざまな他の投稿で推奨されているように設定しました。うまくいきます。間に:clean
タスクを実行することなく、複数回の私のプロジェクトをコンパイルするときしかし、私は、次のエラーメッセージが出ます:Gradle + AndroidAnnotationsが重複したクラスエラーを生成する - すべてのビルドの前にプロジェクトをクリーンアップする必要がある
/project-dir/build/source/apt_generated/flavor1/release/com/example/app/MyActivity_.java:15: error: duplicate class: com.example.app.MyActivity_
[more errors here...]
私はAndroidAnnotationsが:compile
作業前に必ず*_.java
ファイルを再作成するため、シリーズが失敗に複数のビルドと信じています(必要であるかどうかをチェックすることなく)、:compile
タスクは新しいファイルを認識しますが(例えば、タイムスタンプを使用して)、事前にコンパイルされたファイル*.class
を見つけ、エラーを投げます。これは可能ですか?どのように私はこの動作を防ぐことができますか? AndroidAnnotationsの必要性チェックを追加できますか?それとも別の問題ですか?
UPDATE 1:私が手動でapt_generated
フォルダ内*.java
のファイルを削除するときにエラーが:compile
作品以来、AndroidAnnotations自体から投げているようです。
UPDATE 2:それはこのラインなしで動作し、なぜ私は正確に知らない
// Automatically add the generated source code to the source set
android.sourceSets[getSourceSetName(variant)].java.srcDirs += aptOutput
:私は私のbuild.gradle
から次の行を削除
。 Android StudioのMark Directory as > Sources Root
を使ってフォルダを追加していないのでおそらくこれはキャッシングの結果ですか?または、どういうわけか、生成されたJavaファイルを自動的にクラスパスに追加するのはどうですか?
それでも、どんなコメントにも感謝します。
UPDATE 3/SOLUTION
行を削除するとAndroid StudioとGradleのビルドファイルを同期した後、自動生成されたソースコードは、IDEがのエラーを表示させ、ソースルートとして除去しましたクラスがありません。
は最終的に、私はAndroidの注釈githubの問題についての解決策を見つけた:https://github.com/excilys/androidannotations/issues/676
Iソース・セットに追加するための再追加の文(Androidのメーカーはソースルートとしてそれを表示することができます)。さらに、私はこのファイルをバリアントソースコレクションから削除しました。
variant.javaCompile.source = variant.javaCompile.source.filter { p ->
return !p.getPath().startsWith(aptOutputDir.getPath())
}
これで、生成されたファイルは認識され、クラスの重複エラーはなくなりました。
敬具、 デビッド
は、ここに私の最後のbuild.gradleです。私は任意の助けをいただければ幸いです
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
configurations {
// This is the annotations processor dependency configuration.
apt
}
def getSourceSetName(variant) {
return new File(variant.dirName).getName();
}
android {
compileSdkVersion 18
defaultConfig {
versionCode 10
versionName "1.0.2"
targetSdkVersion 17
minSdkVersion 10
}
buildToolsVersion "18.0.1"
buildTypes {
release {
zipAlign true
}
}
productFlavors {
flavor1 {}
}
// This has to go after the productFlavors command (otherwise moving the flavor source set root fails).
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// We move the root of our flavor to support our legacy structure.
flavor1.setRoot('flavors/flavor1')
}
applicationVariants.all { variant ->
aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
// Automatically add the generated source code to the source set
android.sourceSets[getSourceSetName(variant)].java.srcDirs += aptOutput
variant.javaCompile.doFirst {
println "*** Running AndroidAnnotations for ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', aptOutput
]
}
}
}
dependencies {
// Android-Annotations
apt 'com.googlecode.androidannotations:androidannotations:2.7.1'
compile 'com.googlecode.androidannotations:androidannotations-api:2.7.1'
// Include libraries only in flavor1
flavor1Compile fileTree(dir: 'libs', include: '*.jar')
}
:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
configurations {
// This is the annotations processor dependency configuration.
apt
}
def getSourceSetName(variant) {
return new File(variant.dirName).getName();
}
android {
compileSdkVersion 18
defaultConfig {
versionCode 10
versionName "1.0.2"
targetSdkVersion 17
minSdkVersion 10
}
buildToolsVersion "18.0.1"
buildTypes {
release {
zipAlign true
}
}
productFlavors {
flavor1 {}
flavor2 {}
}
// This has to go after the productFlavors command (otherwise moving the flavor source set root fails).
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// We move the root of our flavors to support our legacy structure.
flavor1.setRoot('flavors/flavor1')
flavor2.setRoot('flavors/flavor2')
}
applicationVariants.all { variant ->
def aptOutputDir = project.file("${project.buildDir}/source/apt_generated")
def aptOutput = new File(aptOutputDir, variant.dirName)
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
android.sourceSets[getSourceSetName(variant)].java.srcDirs+= aptOutput.getPath()
variant.javaCompile.doFirst {
println "*** Running AndroidAnnotations for ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', aptOutput
]
}
variant.javaCompile.source = variant.javaCompile.source.filter { p ->
return !p.getPath().startsWith(aptOutputDir.getPath())
}
}
dependencies {
// Android-Annotations
apt 'com.googlecode.androidannotations:androidannotations:2.7.1'
compile 'com.googlecode.androidannotations:androidannotations-api:2.7.1'
// Include libraries only in flavor1
flavor1Compile fileTree(dir: 'libs', include: '*.jar')
}
ここに私の(初期)build.gradle
(私は非関連部分を取り除いた)です:私は、これはあなたのいくつかは役立ちます願っています。
おかげで、 デビッド
私の状況ではまったく何が起こったのですか?ところで、あなたが削除すべき生成ファイルはapp/src/main/java/your/package/nameにあります。 –