Tag: 匕首 2

建造工程时碰撞匕首

当我尝试构建生成Dagger文件的项目生成失败,出现异常。 你能告诉我如何修复它,或者至少在什么方向看。 e:/home/hodzi/Projects/StudioProjects/StackViewer/app/build/tmp/kapt3/stubs/debug/com/hodzi/stackviewer/di/AppComponent.java:6:error:[com.hodzi.stackviewer.questions。 di.QuestionsComponent] com.hodzi.stackviewer.questions.di.QuestionsComponent有冲突的范围:e: e:公共抽象接口AppComponent {e:^ e: com.hodzi.stackviewer.di.AppComponent也有@Singleton e:java.lang.IllegalStateException:未能分析:org.jetbrains.kotlin.kapt3.diagnostic.KaptError:在org.jetbrains.kotlin.analyzer的注解处理时出错。在org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler。)上的org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:138)处的AnalysisResult.throwIfError(AnalysisResult.kt:57) kt:154)at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:58)at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:103)at org.jetbrains .kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)at org.jetbrains.kotlin.daemon.CompileServiceImpl $ compile在org.jetbrains.kotlin.daemon.CompileServiceImpl上编译$ 1 $ 2.invoke(CompileServiceImpl.kt:386) eServiceImpl $ doCompile $$ inlined $ ifAlive $ lambda $ 2.invoke(CompileServiceImpl.kt:889)at org.jetbrains.kotlin.daemon.CompileServiceImpl $ doCompile $$ inlined $ ifAlive $ lambda $ 2.invoke(CompileServiceImpl.kt:96)at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:916)at org.jetbrains.kotlin.daemon.CompileServiceImpl。在sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)上,在org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:385)处编译(CompileServiceImpl.kt:888)。 java:62)at sun.rlect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java :324)at sun.rmi.transport.Transport $ 1.run(Transport.java:200)at […]

用消息“此处不允许的方法”来改写响应代码405

我正在使用改造,我有一个职位请求 interface NetworkApi { @Headers("Content-Type: application/json") @POST("/") fun startLoginRequest(@Body loginModel : LoginModel) : Call<BaseResponseModel> class Factory { var retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build() companion object{ fun getApi (): NetworkApi { val serverApi = NetworkApi.Factory() val api = serverApi.retrofit.create(NetworkApi::class.java) return api } } } } 当我使用这个方法和响应方法时,调用响应体总是空的。 fun startLoginRequest(){ val api = NetworkApi.Factory.getApi() val request = […]

改进API调用:如何确保在进行api调用后该值不为空?

我有下面的AuthenticationResponse模型,我使用retrofit2进行3个API调用。 如果我进行了verifyEmail调用,那么JSON响应主体只包含有效的电子邮件属性(如{“validEmail”:true})。 其他2个调用只包含“resetSuccesful”或其他4的属性。 我怎样才能确保/检查,当我收到verifyEmail调用的响应fe,它包含一个非空的validEmail值? 服务: interface AuthenticationService { @POST("auth/checkEmail") fun verifyEmail(@Body email: String): Call<AuthenticationResponse> @POST("auth/login") fun login(@Body loginCredentials: LoginCredentials): Call<AuthenticationResponse> @POST("auth/resetPassword") fun resetPassword(@Body email: String): Call<AuthenticationResponse> } 模型: data class AuthenticationResponse( val validEmail: Boolean? = null, val loginSuccess: Boolean? = null, val retriesLeft: Int? = null, val authToken: String? = null, val accountBlocked: Boolean? = […]

匕首2.11 – 如何让Activity和Fragment共享共同的价值观?

我目前正在学Android的Dagger 2,我想将Activity的注入注入到Fragment中,但我不知道如何。 这是一个工作设置,显示被注入片段和活动的值。 对不起,代码墙,我简化了我的代码,使其只包含相关的部分。 @Singleton @Component(modules = arrayOf(AndroidSupportInjectionModule::class, AppModule::class, BuildersModule::class)) interface AppComponent { @Component.Builder interface Builder { @BindsInstance fun setApplication(application: Application): Builder fun build(): AppComponent } fun apiService() : ApiService fun inject(app: App) } @Module(subcomponents = arrayOf(MainActivitySubComponent::class, MainFragmentSubComponent::class)) class AppModule @Module abstract class BuildersModule { @Binds @IntoMap @ActivityKey(MainActivity::class) abstract fun bindMainActivity(builder: MainActivitySubComponent.Builder): AndroidInjector.Factory<out Activity> @Binds […]

Dagger不会为androidTest生成组件

我正在面对组件匕首生成的问题,我想为androidTest生成组件,但是当我生成项目时,DaggerTestComponent不会生成。 零件: package com.test.feliperibeirosaruhashi.testingkotlindagger import dagger.Component @Component(modules = arrayOf(MockTestModule::class)) interface MockAppComponent { fun inject(mainActivityTest:MainActivityTest) } 的build.gradle: dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.1.0' testCompile 'junit:junit:4.12' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION" compile "com.google.dagger:dagger:$DAGGER_VERSION" kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION" provided 'org.glassfish:javax.annotation:10.0-b28' kaptTest "com.google.dagger:dagger-compiler:$DAGGER_VERSION" kaptAndroidTest "com.google.dagger:dagger-compiler:$DAGGER_VERSION" androidTestCompile "com.google.dagger:dagger:$DAGGER_VERSION" androidTestCompile "com.android.support.test:runner:$RUNNER_VERSION" […]

匕首2:具有相同键的多个条目

简短的解释 由Components体系结构描述的简化的UML图。 还有一个例外: java.lang.IllegalArgumentException: Multiple entries with same key: gson=com.example.di.AppPresentationComponent and gson=com.example.di.gamesession.GameSessionComponent Dagger 2无法决定从哪个Component提供一个Gson实例。 我永远不会使用多重继承。 你能推荐什么来解决我的情况? 我可以处理GameSessionComponent并将gameSessionManager()移动到GameSessionPresentationComponent 。 它会在我的情况下工作,但这听起来像一个肮脏的解决方案。 有一些代码。 AppComponent: @PerApplication @Component(modules = arrayOf( AppModule::class, TextsModule::class, AudioModule::class, FontsModule::class, TexturesModule::class, QuestModule::class, GameSaveModule::class )) interface AppComponent { fun componentsHolder(): ComponentsHolder fun gdxContext(): GdxContext fun rxHelper(): RxHelper fun textsManager(): TextsManager fun soundsManager(): AudioManager fun fontsManager(): FontsManager fun […]

处理注释时发生了一些错误

当我添加代码int活动 @Inject lateinit var mCommonService:CommonService 错误来了 e:错误:无法访问Nullable e:找不到javax.annotation.Nullable e:有关详细信息,请参阅以下堆栈跟踪。 w:警告:这些选项不被任何注释处理器使用:'[kapt.kotlin.generated]' e:处理注释时发生了一些错误。 请看上面的错误信息。 这是我的模块build.gradle dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' compile 'com.squareup.okhttp3:okhttp:3.8.0' compile 'com.squareup.okhttp3:okhttp-urlconnection:3.8.0' compile 'io.reactivex.rxjava2:rxjava:2.0.1' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' compile 'com.google.dagger:dagger:2.11' kapt 'com.google.dagger:dagger-compiler:2.11' compile 'com.readystatesoftware.systembartint:systembartint:1.0.3' compile […]

匕首2 – 在构造函数中注入默认值

我怎样才能注入这个构造函数: class SomeClass @Inject constructor( dep: Dependency, context: Context, private val otherClass: OtherClass = OtherClass() ) 我只提供依赖和Context …但它说它不能提供OtherClass 。 它应该需要这个类,因为它有一个默认值…我怎样才能做到这一点?

@Inject设置不注入属性

我正在尝试使用Android Dagger‡实现,并将一个DispatchingAndroidInjector注入到我的Application类中: class MyApp : Application(), HasActivityInjector { private lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity> @Inject set override fun onCreate() { super.onCreate() AppInjector.init(this) } override fun activityInjector(): ActivityInjector<Activity> { return dispatchingAndroidInjector } } 但是我得到一个lateinit说明,说明“ lateinit属性没有被初始化”: 06-19 10:57:30.773 10797-10797/com.example.app E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.app, PID: 10797 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.ui.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property dispatchingAndroidInjector has […]

改进泛型类型的调用方法

例如,是否可以创建通用类型的调用? @POST("/service/") fun<T> startRequest(@Body loginReq: Any): Call<T> 那么就像这样调用它 val request = api.startRequest<MyModel_1>(loginReq) 当我这样写和运行的方法,它说: java.lang.IllegalArgumentException: Method return type must not include a type variable or wildcard: retrofit2.Call<T>