代码之家  ›  专栏  ›  技术社区  ›  Mahdi Azadbar

错误:在android studio 3.0中找不到用于将kotlin类添加到java类的符号类

  •  26
  • Mahdi Azadbar  · 技术社区  · 7 年前

    我使用android studio 3.0和一些旧的java类将java转换为Kotlin。之后Kotlin类不能导入java类! 在下面你可以看到我的gradle和我的错误图片。

    模块构建。等级

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.0'
            classpath 'com.google.gms:google-services:3.1.0'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    应用程序级构建。gradle在通常情况下,我使用gradle代码,在android 3.0中,我认为我们需要任何东西

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 25
        buildToolsVersion '26.0.2'
        defaultConfig {
            applicationId "com.idehnavazan.beautifierclient"
            minSdkVersion 14
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        dataBinding {
            enabled = true
        }
    
    
    }
    repositories {
        mavenCentral()
        jcenter()
        maven { url 'https://maven.google.com' }
        maven { url 'https://jitpack.io' }
    
    
    }
    dependencies {
        compile 'com.android.support:multidex:1.0.1'  
        compile 'com.android.support:appcompat-v7:25.3.1'
        compile 'com.github.rey5137:material:1.2.2'
        compile 'com.android.support:cardview-v7:25.3.1'
    
    }
    apply plugin: 'com.google.gms.google-services'
    

    enter image description here

    4 回复  |  直到 5 年前
        1
  •  63
  •   Eugen Pechanec    7 年前

    要使用Kotlin文件,需要将Kotlin添加到项目中。

    项目/构建。格拉德尔

    buildscript {
        ext.kotlinVersion = '1.1.51'
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        }
    }
    

    项目/模块/构建。格拉德尔

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
    

    下一步是什么

    由于您使用的是support library 25.3.1和Android plugin 3.0.0,您的下一个问题可能是: style attribute '@android:attr/windowEnterAnimation' not found .

        2
  •  1
  •   Fakhar    5 年前

    我在单独的文件夹中添加了所有kotlin类,这对我来说很有用! 将java类与kotlin分开。我正在吃

    app:compileDebugJavaWithJavac Kotlin class calling from java:  error: cannot find symbol 
    

    编译时错误。

        3
  •  0
  •   bboyairwreck    4 年前

    我的问题是,我已经使用 testImplementation 而不是 implementation 模块gradle文件的内部,该文件将您的模块声明为依赖项。

    更改依赖项声明为我修复了它。

        4
  •  0
  •   LaurentBaj    3 年前

    我也是kotlin/android的新手,使用的是ViewBinding。发生这种类型的错误时,我正在重命名一个xml文件。我刚刚补充说:

    dataBinding {
            enabled = true
        }
    

    到构建。gradle(模块)-文件,现在可以工作了。老实说,我从未理解视图绑定和数据绑定之间的区别