无法在 Android Studio 中执行复制粘贴

Tea*_*ava 11 windows ide android android-studio

我在 Android Studio 中遇到了两个主要问题。首先,我无法在某些课程中执行复制粘贴剪切粘贴( ctrl+ c- ctrl+ v- ctrl+ x) 功能。为了解决这个问题,我点击了“invalide caches/restarts”,但它立即再次崩溃。

第二个问题是(我认为它与第一个问题有关)编译器无法识别已经定义的方法和属性。自动建议等不起作用。

我为尝试解决问题而采取的步骤是;

  1. 文件 -> 无效缓存/重启,
  2. 文件 -> 省电模式 -> 禁用,
  3. 关闭所有打开的标签并重新启动,
  4. 文件 -> 将项目与 Gradle 文件同步,
  5. 文件 -> 与文件系统同步,
  6. 删除JDK并重新安装,
  7. 删除Android Studio并重新安装,
  8. 删除已下载的 SDK 文件和“.Android”文件夹,
  9. 禁用并删除所有插件。
  10. 在文件 -> 设置 -> 键盘映射中检查复制粘贴键盘映射
  11. 将项目从 bitbucket 拉到不同的 2 台计算机
  12. 创建新项目,使用 NotePad++ 将整个项目类复制到新项目
  13. 尝试将所有Java代码转换为Kotlin,无法转换

这是我的系统规格;Windows 10 家庭单语言 (TR),版本 1909。16 GB 内存。Android Studio 3.5.3 和 Gradle 版本 3.5.3

我已经阅读了所有关于同一问题的帖子,但没有运气(这些帖子仅关于 MAC 和 Linux 平台)。

UPDATE 1.0 -> 我发现有些类不能执行上述操作,但有些类可以。

我意识到,不能执行我上面描述的操作的类没有图标。(有时会神奇地出现“J”图标,当我点击另一个类时,这个 J 图标会立即消失。)我认为 Android Studio 的 gradle 或文件系统不会将这些文件识别为类。

更新 2.0 -> 我注意到当我单击 DuoFragment 的 Structure 部分(其中有 500 多行代码和未编译的类之一)时,无法加载任何内容。DuoFragment 的尺寸是否更大以进行处理?

另外在查看Build部分时,有些进程无法运行(不知道是否正常);

  • 任务 :app:compileDebugAidl NO-SOURCE,
  • 任务 :app:compileDebugRenderscript NO-SOURCE,
  • 任务 :app:processDebugJavaRes NO-SOURCE

更新 3.0 ->

这是我的 Gradle 文件。项目级 Gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()


    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

应用级 Gradle 文件。

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.lotusif.dump2"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.core:core:1.1.0'

    // material widgets
    implementation 'com.google.android.material:material:1.2.0-alpha03'

    // progress bar with text 
    implementation "com.github.skydoves:progressview:1.0.3"

    // sequence progress
   implementation 'com.github.transferwise:sequence-layout:1.0.11'

    // flash bar
   implementation 'com.andrognito.flashbar:flashbar:1.0.2'

    // toggle - switch button
   implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'

    // Custom Toast message
    implementation 'com.github.GrenderG:Toasty:1.4.2'

    // liquid effect bar
    implementation 'com.mikhaellopez:circularfillableloaders:1.3.2'

    // bubble tab bar
    implementation 'com.fxn769:bubbletabbar:1.0.3'

    //glide image library
    implementation 'com.github.bumptech.glide:glide:4.10.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

    // scaling layout
    implementation 'com.github.iammert:ScalingLayout:1.2.1'

    // lottie animation
    implementation 'com.airbnb.android:lottie:3.3.1'

    //Gson
    implementation 'com.google.code.gson:gson:2.8.6'

    //RxJava
    implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

    implementation 'com.daimajia.easing:library:2.1@aar'
    implementation 'com.daimajia.androidanimations:library:2.3@aar'

    //retrofit
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'

}
Run Code Online (Sandbox Code Playgroud)

没有建议 键盘映射 安卓版 如果我不添加额外的代码,Gradle 同步成功

更新 1.0 图像

没有图标或只有“J”图标的类不能进行操作

当我点击/打开另一个课程时,“J”图标消失了

更新 2.0 图像

某些过程无法在构建部分完成 无法加载 DuoFragment 结构 DuoFragment 代码总结

Tea*_*ava 3

更新 --> Windows 10 单语言土耳其语的 Kotlin 库中存在错误。(也许其他一些单语言 Windows 发行版也有同样的问题,我还不知道。)Kotlin 的一些库无法在土耳其操作系统上运行。我通过安装Windows 10 Pro English解决了这个问题。

其他使用 Windows 10 单语言土耳其语的开发人员从不同的角度面临着同样的问题。(示例1示例2

旧答案

TL;DR -> 问题与使用Kotlin编写的第三方库有关。我已将 Java 项目转换为 Kotlin,所有有问题的第三方库都运行良好。问题是关于 Java-Kotlin 冲突

我想分享一下我是如何解决这个问题的,供以后遇到此类问题的人参考。

我一一完成了上面提到的所有步骤,但找不到任何解决方案,因此我决定检查我的第三方库。

首先,我禁用了所有第三方库,并查看了无法识别已定义方法和属性的类的状态。在禁用第三方库并进行 Rebuild Project 和 Sync Gradle 后,那些损坏的类的自动建议功能再次开始工作。然后,发现哪些第三方库有问题,我一一激活了这些第三方库。我发现哪些第三方库破坏了我的项目。

有 4 个第三方库破坏了我的项目:StickySwitchProgressViewSequenceLayoutFlashbar。当我删除这些库时,一切正常。删除库后,我的 Gradle 文件如下。

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.lotusif.dump2"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.core:core:1.1.0'

    // material widgets
    implementation 'com.google.android.material:material:1.2.0-alpha03'

    // progress bar with text BUGGY!
    // implementation "com.github.skydoves:progressview:1.0.3"

    // sequence progress BUGGY !
    // implementation 'com.github.transferwise:sequence-layout:1.0.11'

    // flash bar BUGGY !
    // implementation 'com.andrognito.flashbar:flashbar:1.0.2'

    // toggle - switch button BUGGY !
    // implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'

    // Custom Toast message
       implementation 'com.github.GrenderG:Toasty:1.4.2'

    // liquid effect bar
       implementation 'com.mikhaellopez:circularfillableloaders:1.3.2'


    // bubble tab bar
       implementation 'com.fxn769:bubbletabbar:1.0.3'

    // android chart library
       implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

    //glide image library
    implementation 'com.github.bumptech.glide:glide:4.10.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

    // scaling layout
    implementation 'com.github.iammert:ScalingLayout:1.2.1'

    // lottie animation
    implementation 'com.airbnb.android:lottie:3.3.1'

    //Gson
    implementation 'com.google.code.gson:gson:2.8.6'

    //RxJava
    implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

    implementation 'com.daimajia.easing:library:2.1@aar'
    implementation 'com.daimajia.androidanimations:library:2.3@aar'

    //retrofit
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
}
Run Code Online (Sandbox Code Playgroud)

那么,那些破坏我的项目的库的共同特征是什么?我的项目是用Java编写的,但该库是用Kotlin编写的。等一下,我不能在我的 Java 项目中使用 Kotlin 库吗?我可以。我必须在我的gradle.propertiesandroid.useAndroidX=true中添加and ,就是这样。但是,如果我已经在gradle.properties中添加了这些行但它不起作用怎么办?android.enableJetifier=true

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)

我不明白为什么 kotlin 库不能与我的 Java 项目一起使用。正如您在我的Gradle 文件中看到的,我正在使用apply plugin: 'kotlin-android'apply plugin: 'kotlin-android-extensions'来支持 Kotlin。

我是如何拯救我的项目的?据我所知,有两个可用的选项。第一种方法是删除这 4 个第三方库并且无法使用它们,第二种方法是将所有 Java 类转换为 Kotlin 类(我之前尝试过,但直到禁用所有第三方库才起作用)。我选择将所有 Java 类转换为 Kotlin 类。因此,我能够使用上面提到的 4 个第三方库。

我花了30天的时间才解决这个问题。现在,我正在研究 Kotlin 语言。结果,我的项目运行没有任何问题。