Tag: 匕首 2

Android Kotlin匕首2 ViewModel注入错误

我想在我的项目上使用新的ViewModel从拱门Android库。 我在github上学习了很多示例项目。 最后,我想在我的项目上实现这个架构,但是我无法构建它。 Gradle控制台: ….AppComponent.java:6: error: [dagger.android.AndroidInjector.inject(T)] kibar.app.ui.fragment.HomeFragmentViewModel cannot be provided without an @Inject constructor or from an @Provides-annotated method. e: public abstract interface AppComponent { e: ^ e: kibar.app.ui.fragment.vpresenter.home.HomeFragmentViewModel is injected at e: kibar.core.di.ViewModelModule.bindHomeViewModel(model) e: java.util.Map<java.lang.Class<? extends android.arch.lifecycle.ViewModel>,javax.inject.Provider<android.arch.lifecycle.ViewModel>> is injected at e: kibar.core.di.viewmodel.ViewModelFactory.<init>(creators) e: kibar.core.di.viewmodel.ViewModelFactory is injected at e: kibar.app.ui.fragment.HomeFragment.viewModelFactory e: kibar.app.ui.fragment.HomeFragment is injected […]

匕首2与Kotlin的多重绑定

我的匕首2模块中有以下代码片段 @Singleton @Provides @ElementsIntoSet fun providesQueries(foo: Foo): Set<Foo>{ val queries = LinkedHashSet<Foo>() queries.add(foo) return queries } 我试图用这种方式注入 @Inject lateinit var foo: Set<Foo> 但匕首显示一个错误,说匕首不能提供没有@Provides或@Produces方法的java.util.Set。 我在java中做了同样的工作。 有人知道为什么它失败?

Dagger2和Kotlin运行失败的原因是:app:compileDebugKotlinAfterJava

我试图在测试应用程序中实施Dagger 2,以Kotlin语言学习清洁架构和依赖注入。 编辑: 我可以编译感谢@Logain,但我一直在我的单身(见我的TaskWorker下面)的匕首静态成员问题,所以我在找我该如何解决这个错误 但是,我得到了一个问题,我的DaggerComponent是很好地生成,当我重建 ,但不是当我想运行我的应用程序进行测试,它失败并消失。 它失败,出现这个错误: 错误:(21,29)未解决的引用:DaggerInjectorComponent 错误:执行任务':app:compileDebugKotlinAfterJava'失败。 >编译错误。 查看日志了解更多详情 而当我做一个重建,这个任务正确传递 :app:compileDebugKotlinAfterJava 所以我不明白为什么失败。 这是我的InjectorComponent : @Singleton @Component(modules = arrayOf(ContextDaggerModule::class, LocalStoreDaggerModule::class)) interface InjectorComponent { fun inject(realmLocalStore: RealmLocalStore) fun inject(taskWorker: TaskWorker) } ContectDaggerModule : @Module class ContextDaggerModule (val app: Application) { @Provides @Singleton fun provideContext(): Context = app @Provides @Singleton fun provideApplication(): Application = app @Provides […]

错误:error.NonExistentClass Kotlin在多模块Dagger项目中

我正在使用Dagger 2和Kotlin进行Android开发。 而我的项目也是一个多模块项目。 我的settings.gradle文件是这样的 include :app include :lib 我也维护lib模块。 在匕首文件(例如在组件中),我尝试从其他模块获取项目。 例如: @Component interface AppComponent{ fun getPresenter() : Presenter } Presenter对象在lib模块中定义。 我在linux环境下工作,我正在使用android studio 3预览Canary 5.代码运行良好,我可以生成APK。 但之后我的公司希望我使用稳定版本的Android Studio生成APK。 然后我使用Android Studio 2.3.3 当我编译Android项目时,我遇到了这个错误 error: error.NonExistentClass 出现错误时 :app:kaptDebugKotlin 是由匕首类执行并造成的,找不到在其他项目中定义的类。 我能做些什么来解决这个问题? 对不起,我的英语不好。

Moshi的定制适配器与RxAndroid&Retrofit&Kotlin

在为Android项目配置Kotlin之后,我写了一个简单的MainActivity.kt 。 它调用Retrofit来获取包含以下数据的JSON文件: { “消息”:“成功”, “user”:{ “用户名”:“Eric” } } 现在我想用Moshi把JSON数据转换成Kotlin类,所以这里有两个类来反映上面的JSON结构: class User(var username:String) UserJson类(var消息:字符串,var用户:用户) 而Moshi的自定义类型适配器: 类UserAdapter { @FromJson fun fromJson(userJson:UserJson):User { Log.d(“MyLog”,“message = $ {userJson.message}”)// =成功 Log.d(“MyLog”,“user = $ {userJson.user}”)// = null 返回userJson.user } } 当它进入函数从fromJson() , userJson.message = "success"的预期。 但奇怪的是, userJson.user是null ,这应该是User(username="Eric") 。 我是Moshi和Kotlin的新手,我已经坚持了这个问题约10个小时。 请帮我一下 感谢您的帮助。 ======================================== 以下是MainActivity.kt的完整代码(仅限50行): class MainActivity:AppCompatActivity(){ 重写fun onCreate(savedInstanceState:Bundle?){ super.onCreate(savedInstanceState) 的setContentView(R.layout.activity_main) […]

Android:匕首Kotlin

我是匕首新手。 我想用Dagger 2在我的项目上使用Dependecy Injection系统。 当我调试我的项目注入字段显示为null 。 怎么了? class App : Application() { lateinit var component: AppComponent @Inject lateinit var database: AppDatabase //–> null?? @Inject lateinit var app: App //–> null?? override fun onCreate() { super.onCreate() component = DaggerAppComponent.builder() .appModule(AppModule(this)) .databaseModule(DatabaseModule()) .build().apply { inject(this@App) Timber.d("App: $app") } } } @AppScope @Component(modules = arrayOf(AppModule::class, DatabaseModule::class)) interface AppComponent […]

你如何在Kotlin中用Dagger 2注入命名的字段参数?

我有一个Java中的命名参数,我注入以下方式: @Inject @Named("io") Scheduler ioScheduler; 我如何在Kotlin中做到这一点?

使用“kotlin-kapt”插件,Android Studio不提供有关Dagger 2的具体错误

我用Dagger 2使用Kotlin。问题是,当我在执行Dagger的时候犯了错误(比如错过@Inject for class constraint),IDE并没有具体显示错误在哪里。 Insead编译器的错误总是一样的: Execution failed for task ':app:kaptDebugKotlin'. Internal compiler error. See log for more details 有故意错误的类(注释@Inject): class LoginPresenter //@Inject constructor(private val request: LoginRequest) 项目build.gradle文件: buildscript { ext.kotlin_version = '1.1.4-3' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { jcenter() } } task clean(type: Delete) […]

匕首2不识别Kotlin的提供方法。 Java工作正常

匕首不认可Kotlin提供的一种方法。 这是模块的重要部分: @Provides @AppScope fun provideClient(cache: Cache, interceptors: List<Interceptor>?): OkHttpClient { val httpBuilder = OkHttpClient.Builder() interceptors?.let { for (interceptor in interceptors) { httpBuilder.addInterceptor(interceptor) } } return httpBuilder .cache(cache) .build() } @Provides @AppScope fun provideInterceptors(): List<Interceptor>? { return listOf(HttpLoggingInterceptor().setLevel(WebServiceConfig.LOGGING_LEVEL)) } 错误消息如下所示: AppComponent.java:15: error: java.util.List<? extends okhttp3.Interceptor> cannot be provided without an @Provides-annotated method. 如果我使用MutableList,那么它工作。 所以问题是:Dagger2 / […]

匕首和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: […]