2017-11-01 11 views
1

나는 다음과 같은 문제에 봉착 : - 만든 몇 가지 모듈 Component 클래스를 구현하며 @AutoService(Component::class) 주석의 - 내 안드로이드 응용 프로그램은 이러한 클래스를 검색 할 ServiceLoader을 사용하고 있습니다. 그러나 어떤 이유로 kaptMETA-INF/services/...코 틀린 주석 프로세서 + 자동차 서비스

내 모듈 gradle.file 내부의 파일을 생성되지 않습니다

apply plugin: 'com.android.library' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-kapt' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.2" 


    defaultConfig { 
     minSdkVersion 19 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

     javaCompileOptions { 
      annotationProcessorOptions { 
       includeCompileClasspath = true 
      } 
     } 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

} 

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

    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
    implementation 'com.android.support:design:26.1.0' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 

    implementation project(':common-dependencies') 
    implementation project(':component') 
    compileOnly 'com.google.auto.service:auto-service:1.0-rc3' 
    kapt "com.google.auto.service:auto-service:1.0-rc3" 

    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 
} 

내 앱의 build.gradle 파일 : 나는 이유를 모르겠어요

apply plugin: 'com.android.application' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-android-extensions' 
apply plugin: 'kotlin-kapt' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.2" 
    defaultConfig { 
     applicationId "com.test.sampleapp" 
     minSdkVersion 19 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

     javaCompileOptions { 
      annotationProcessorOptions { 
       includeCompileClasspath = true 
      } 
     } 
    } 

    flavorDimensions 'required-notused' 

    productFlavors { 
     brandA { 
      resValue "string", "app_name", "Brand A" 
     } 
     brandB { 
      resValue "string", "app_name", "Brand B" 
     } 

     all { applicationIdSuffix ".${it.name.toLowerCase()}" } 
    } 

    buildTypes { 
     debug 

     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 
dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 

    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
    implementation 'com.android.support:design:26.1.0' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 

    implementation project(':common-dependencies') 
    implementation project(':component') 

    brandAImplementation project(':city-picker') 
    brandAImplementation project(':profile') 
    brandAImplementation project(':matches') 
    brandAImplementation project(':chat') 

    brandBImplementation project(':city-picker') 
    brandBImplementation project(':chat') 

    compileOnly 'com.google.auto.service:auto-service:1.0-rc3' 
    kapt "com.google.auto.service:auto-service:1.0-rc3" 
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 
} 

repositories { 
    mavenCentral() 
} 

, 그러나 kapt은 기본적으로 해당 파일을 생성하지 않습니다. Java 클래스를 사용하면 즉시 생성됩니다. 그 이유는 무엇입니까?

답변

0
나는 내 자신의 프로세서를 인스턴스화했다 (그것을 자랑하지 않음) 작동 을 항상 processingOver로를 대체 해결 방법을했다

false를 반환합니다. kapt가 내 리소스의 캐시를 유지 한 것으로 보이고 빌드를 정리 한 후 더 이상 파일을 생성하지 않습니다.

public class CustomAutoServiceProcessor extends AutoServiceProcessor { 

    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 
     try { 
      Field processingOver = roundEnv.getClass().getDeclaredField("processingOver"); 
      processingOver.setAccessible(true); 
      processingOver.set(roundEnv, false); 
     } catch (NoSuchFieldException e) { 
      e.printStackTrace(); 
     } catch (IllegalAccessException e) { 
      e.printStackTrace(); 
     } 
     return super.process(annotations, roundEnv); 
    } 
} 

더 좋은 제안을 환영합니다 :

는 여기 코드입니다!

+0

이것은 작은 소리의 프로젝트에서 이것을 재현 할 수있는 경우 Kotlin 문제 추적기에보고하십시오 (버그 번호 : ). http://kotl.in/issue). – yanex