Tag: 匕首 2

无法转换为org.jetbrains.kotlin.java.model.types.JeClassInitializerExecutableTypeMirror

我想升级到匕首2.8 – 但是现在我的项目在编译时会抛出这个错误: :android:compileWithAnalyticsWithCloudProdDebugAndroidTestKotlinAn exception occurred during annotation processing. Stacktrace: java.lang.ClassCastException: org.jetbrains.kotlin.java.model.types.JeMethodExecutableTypeMirror cannot be cast to org.jetbrains.kotlin.java.model.types.JeClassInitializerExecutableTypeMirror at org.jetbrains.kotlin.annotation.processing.impl.KotlinTypes.isSubsignature(KotlinTypes.kt:275) at dagger.shaded.auto.common.Overrides$ExplicitOverrides.isSubsignature(Overrides.java:183) at dagger.shaded.auto.common.Overrides$ExplicitOverrides.overrides(Overrides.java:109) at dagger.shaded.auto.common.MoreElements.getLocalAndInheritedMethods(MoreElements.java:334) at dagger.shaded.auto.common.MoreElements.getLocalAndInheritedMethods(MoreElements.java:314) at dagger.internal.codegen.ComponentValidator.validate(ComponentValidator.java:165) at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:123) at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:47) at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:329) at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:182) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.doRound(AnnotationProcessingExtension.kt:346) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.process(AnnotationProcessingExtension.kt:283) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.doAnnotationProcessing(AnnotationProcessingExtension.kt:269) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.analysisCompleted(AnnotationProcessingExtension.kt:140) at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:119) at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(TopDownAnalyzerFacadeForJVM.kt:66) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.analyze(KotlinToJVMBytecodeCompiler.kt:365) at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:126) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:358) […]

Dagger2不能访问为空。 未findjavax.annotation.Nullable

我有一个模块来提供一个Retrofit界面。 @Module class NetModule(val base: String) { @Provides @Singleton fun provideOkHttpClient(): OkHttpClient { return OkHttpClient.Builder() .addInterceptor(object: Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val request = chain.request() info(“Request for ${request.url()}”) return chain.proceed(request) } }).build() } @Provides @Singleton fun provideGson(): Gson { return GsonBuilder() .enableComplexMapKeySerialization() .serializeNulls() .setPrettyPrinting() .setLenient() .create() } @Provides @Singleton fun provideRetrofit(OkHttpClient: OkHttpClient, […]

我可以在Kotlin中使用Dagger 2的现场注射吗?

我发布了一个问题( Dagger 2不会生成组件类(Android,Kotlin) ),经过一些实验,似乎问题可能是由于Kotlin隐藏了该字段。 class CoffeeShop { @Inject var TheCoffee:Coffee? = null; } 错误信息是, :app:kaptDebugKotline: …\CoffeeShop.java:7: error: Dagger does not support injection into private fields e: private ….Coffee TheCoffee; TheCoffee在我的源代码中不是私有的。 但我认为Kotlin可能是翻译 class CoffeeShop { @Inject var TheCoffee:Coffee? = null; } 转换成Java代码 class CoffeeShop { @Inject private Coffee TheCoffee = null; public Coffee getTheCoffee(); public void […]

kapt构建失败与匕首Android处理器

我试图用Kotlin注解处理工具 (kapt)在我的项目中包含Dagger Android处理器( 在此记录)。 我已经在我的build.gradle文件中包含了适当的依赖关系: apply plugin: ‘com.android.application’ apply plugin: ‘kotlin-android’ apply plugin: ‘kotlin-kapt’ android { compileSdkVersion 25 buildToolsVersion “25.0.2” defaultConfig { applicationId “com.example.app” minSdkVersion 16 targetSdkVersion 25 versionCode 1 versionName “1.0” testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” } sourceSets { main.java.srcDirs += ‘src/main/kotlin’ } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’ } } } dependencies { […]

使用Kapt和Dagger2进行注释处理时出错

我花了一些时间与我的错误,但没有任何积极的结果,所以我可能有人可以帮助。 我的项目中有3个模块:应用程序(android),数据,域 – 都是纯kotlin。 所有DI都在应用程序模块中。 ApplicationComponent&ApplicationModule: @Singleton @Component(modules = arrayOf(ApplicationModule::class, NavigatorModule::class, RepositoryModule::class, FirebaseModule::class, SchedulerModule::class, UseCaseModule::class)) interface ApplicationComponent { fun injectApplication(application: Application) fun loginSubComponent() : LoginSubComponent } @Module class ApplicationModule(private val application: Application) { @Provides @Singleton fun provideApplication() = application } @Module class UseCaseModule { @Provides @Singleton fun provideLoginAccountUseCase(scheduler: ComposeScheduler, repository: AccountRepository) = LoginAccountUseCase(scheduler, repository) @Provides […]

未解决的参考DaggerApplicationComponent

我试图创建我的应用程序组件,但匕首不生成我的应用程序组件。 这里是MyApplication类 class MyApplication : Application() { companion object { @JvmStatic lateinit var graph: ApplicationComponent } @Inject lateinit var locationManager : LocationManager override fun onCreate() { super.onCreate() graph = DaggerApplicationComponent.builder().appModule(AppModule(this)).build() graph.inject(this) } } 这里是我的AppComponent类 @Singleton @Component(modules = arrayOf(AppModule::class)) interface ApplicationComponent { fun inject(application: MyApplication) } 这里是截图 这是我在github上的 项目 这里是错误日志 Error:(7, 48) Unresolved reference: DaggerApplicationComponent Error:(28, […]

匕首和Kotlin。 匕首不生成组件类

我是新的kotlin和匕首。 我有一个小问题,我不怎么解决,我找不到解决方案。 所以这就是我所拥有的 @Module class AppModule (app: Application) { private var application: Application; init { this.application = app; } @Provides fun provideApplication(): Application? { return application; } @Provides fun provideResources(): Resources? { return application.resources; } } @Singleton @Component(modules = arrayOf(AppModule::class)) interface AppComponent: AppComponentBase { public class Initializer { private constructor(){} companion object { fun Init(app: […]

房间+匕首2. NPE

使用房间+ LiveData + Dagger2 + Kotlin 分贝代码: @Database(entities = arrayOf(MonthlyBudget::class, Purchase::class), version = 1, exportSchema = false) @TypeConverters(DateTypeConverter::class) abstract class AppDatabase : RoomDatabase() { abstract fun budgetDAO(): BudgetDAO abstract fun purchaseDAO(): PurchaseDAO } 在提供db的dagger2中的方法 @Provides fun providesAppDatabase(context: Context): AppDatabase = Room.databaseBuilder(context, AppDatabase::class.java, “my-budget-db”).allowMainThreadQueries().build() 在匕首2中返回null的方法 @Provides @Singleton @Named(“CurrentMonthBudget”) fun provideCurrentMonthBudget(repository: AppRepository): MonthlyBudget = repository.currentMonthBudget() 对象的注入 @Inject […]

匕首2活动不能提供@提供或@产生注释的方法

我是新来的匕首,我试图实现一个从注入正在发生的类inheritance的类。 当我在MainActivity中注入一个组件并从BaseActivityinheritance它时,事情就破灭了。 我的AppComponentClass: @Singleton @Component(modules = {NetworkModule.class, ApplicationModule.class, AndroidModule.class}) public interface AppComponent { void inject (BaseActivity baseActivity); void inject (MainActivity mainActivity); } } 我的ActivityModule类: @Module public class ActivityModule { private Activity activity; public ActivityModule(Activity activity) { this.activity = activity; } @PerActivity @Provides @ActivityContext public Context provideContext() { return activity; } } 我的ApplicationModule类: @Module public class […]

匕首2:无法在Intellij Idea(Kotlin)中find生成的类

我试图写一个应用程序来理解火花和匕首2.但无法使用生成的匕首文件。 这个问题有很多类似的问题,但是我不能用这些问题来解决问题。 我的项目可以在这里findgithub build.gradle文件看起来像这样 … apply plugin: ‘kotlin-kapt’ dependencies { compile “org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version” compile “com.sparkjava:spark-kotlin:$spark_kotlin_version” compile “org.slf4j:slf4j-log4j12:$slf4j_version” compile “com.google.dagger:dagger:$dagger_version” kapt “com.google.dagger:dagger-compiler:$dagger_version” testCompile group: ‘junit’, name: ‘junit’, version: ‘4.12’ } …. 这是我试图注入的SparkSetup.kt类。 这个模块和组件存在于co.pissarra.util.dagger包中 SetupModule.kt的内容如下所示 @Module class SetUpModule { @Provides @Singleton fun provideSparkSetup() : SparkSetup { return SparkSetup() } } 这是AppComponent.kt类 @Singleton @Component(modules = arrayOf(SetUpModule::class)) interface AppComponent { […]