未解决的参考匕首2 + Kotlin + Android Gradle

编程入门 行业动态 更新时间:2024-10-18 12:24:16
本文介绍了未解决的参考匕首2 + Kotlin + Android Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用Kotlin在一个Android项目中测试Dagger 2.我的灵感来自 Android Clean Architecture 存储库.我的gradle构建中有两个模块,一个是"app",一个是"module".模块包含一个类调用模型.在我的应用gradle模块中,我使用模型提供程序创建了一个名为"DaggerModule"的Dagger模块.当我尝试构建项目时,出现编译错误:

I'm testing out Dagger 2 with Kotlin in an Android project. I was inspired by the Android Clean Architecture repo. I have two modules in my gradle build, one is "app" and one is "module". Module contains one class call Model. In my app gradle module I created a dagger module called "DaggerModule" with a Model provider. When I try to build the project, I get compilation errors:

DaggerModule.kt: (3, 57): Unresolved reference: Model DaggerModule.kt: (9, 34): Unresolved reference: Model DaggerModule.kt: (9, 42): Unresolved reference: Model

当我尝试将Model类从模块"模块移至应用"模块内部时,所有编译均会出现错误.试图弄清楚我是在做愚蠢的事情,还是应该在某个地方提交错误.

When I try moving the Model class from "module" module to inside of the "app" module everything compiles w/o error. Trying to figure out if I'm doing something stupid, or if I should file a bug somewhere.

有问题的文件的摘要在这里供参考:

For reference here the snippets of the problematic files:

---- app/build.gradle buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.2.3' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.1218' } } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' repositories { jcenter() mavenCentral() } android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.github.app.kotlin_unresolved_reference.app" minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_6 targetCompatibility JavaVersion.VERSION_1_6 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':module') compile 'com.android.support:appcompat-v7:22.2.1' kapt "com.google.dagger:dagger-compiler:2.0.1" compile "com.google.dagger:dagger:2.0.1" compile "javax.annotation:javax.annotation-api:1.2" compile "org.jetbrains.kotlin:kotlin-stdlib:0.12.1218" } --- module/build.gradle apply plugin: 'java' //noinspection GroovyUnusedAssignment sourceCompatibility = 1.7 //noinspection GroovyUnusedAssignment targetCompatibility = 1.7 configurations { provided } sourceSets { main { compileClasspath += configurations.provided } } dependencies { provided "com.google.dagger:dagger-compiler:2.0.1" compile "com.google.dagger:dagger:2.0.1" compile "javax.annotation:javax.annotation-api:1.2" compile "org.jetbrains.kotlin:kotlin-stdlib:0.12.1218" } --- DaggerModule.kt Module public class DaggerModule { Provides fun provideModel(): Model = Model() } ---- Model.kt public class Model { }

免责声明:这是我第一次驾驶Dagger 2,并且是摇篮新人.示例项目是我发现该问题的最低代码.我不期望它会做很多事情:D.

DISCLAIMER: This is my first time test driving Dagger 2 and am a gradle newb. The sample project is the minimum code I could find to display the problem. I'm not expecting it to do much :D.

推荐答案

您的 module/build.gradle 设置为java而不是kotlin.我已经将其修改为以下内容,并且可以正常编译.

Your module/build.gradle is set to java instead of kotlin. I have modified it to the following and it compiles ok.

buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.1218' } } apply plugin: 'kotlin' dependencies { kapt "com.google.dagger:dagger-compiler:2.0.1" compile "com.google.dagger:dagger:2.0.1" compile "javax.annotation:javax.annotation-api:1.2" compile "org.jetbrains.kotlin:kotlin-stdlib:0.12.1218" }

更多推荐

未解决的参考匕首2 + Kotlin + Android Gradle

本文发布于:2023-10-31 04:33:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545020.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:匕首   Kotlin   Gradle   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!