【问题标题】:Can Not Perform Copy-Paste in Android Studio无法在 Android Studio 中执行复制粘贴
【发布时间】:2019-12-28 16:10:29
【问题描述】:

我在 Android Studio 中遇到了两个主要问题。首先我不能执行 copy-pastecut-paste (ctrl+c - ctrl+v - ctrl+x) 某些职业的能力。为了解决这个问题,我点击“无效缓存/重新启动”,但它立即再次崩溃。

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

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

  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 平台)。

更新 1.0 -> 我发现有些类不能做上述操作,但有些类可以。

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

更新 2.0 -> 我注意到,当我单击 DuoFragment 的结构部分(其中有 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
}

应用级 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'

}

更新 1.0 图片

更新 2.0 图片

【问题讨论】:

  • 你能提供你的 Android Studio 的完整截图吗?失败的构建/gradle 同步(请参阅事件日志或运行)可能会破坏功能。
  • 添加了 Android Studio @JakeSteam 的完整截图。 Gradle 同步成功,如果我不添加任何额外的代码 sn-p。 (我整个项目代码来自Bitbucket)
  • 您是否检查过复制和粘贴是否在浏览器或文本编辑器等其他地方工作?
  • 是的,它有效。它不能只工作某些类(就像我说的 DuoFragment() 类)@SanketVekariya
  • 你能告诉我们你的 build.gradle 吗? (来自项目和主模块)。您是否为项目定义了特定的 java.source 位置?

标签: android windows android-studio ide


【解决方案1】:

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

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

老答案

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

我想与以后遇到此类问题的人分享我是如何解决问题的。

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

首先,我禁用了所有第三方库,并查看了无法识别已定义方法和属性的类的状态。在禁用第三方库并重新构建项目和同步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'
}

那么,那些破坏我的项目的库的共同特征是什么?我的项目是用 Java 编写的,但库是用 Kotlin 编写的。一秒钟,我不能在我的 Java 项目中使用 Kotlin 库吗? Yes, I can。我必须在我的gradle.properties 中添加android.useAndroidX=trueandroid.enableJetifier=true,就是这样。但是如果我已经在我的 gradle.properties 中添加了这些行并且它没有工作怎么办?

# 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

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

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

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

【讨论】:

  • 我认为这与那些库(或您的应用程序)使用 androidx 的事实有关,而不是因为 Kotlin。 Kotlin 编译结果与 java 代码完全相同。看看这个关于androidx的:developer.android.com/jetpack/androidx/…
  • 是的,我已经阅读了这篇文章,但我不明白我的项目的确切问题是什么。 @zapotec
  • 老实说,如果这不是你的问题,我帮不了你。如果您的 gradle.properties 中已经有“android.useAndroidX=true”和“android.enableJetifier=true”,那么您的 AndroidStudio 无法正确管理代码是没有意义的。我在自己的项目中有一些 Kotlin 库(例如 OkHttp4),我不需要在 Kotlin 中重新编写我的代码。此外,我什至不需要将 kotlin 插件添加到我的 gradle 文件中......无论如何,很高兴你能解决我迁移到 Kotlin 的问题!
  • 有很多开发者一起使用这种库。他们中的大多数人没有遇到任何问题,但我遇到了。我试图弄清楚这是否是一个 AS 错误。我检查了我的班级大小(可能单个片段中的 500 多行破坏了我的项目等)但没有任何作用。最后我找到了 2 个修复选项。正如我之前所说,我花了 30 天时间才弄清楚问题所在。我没有找到问题的确切原因,但我找到了解决方法@zapotec
  • 我要感谢你!一个月以来,我没有使用警告、自动完成等功能……我们怎么知道它是关于土耳其操作系统的……
猜你喜欢
  • 2018-08-21
  • 2020-09-12
  • 2012-05-07
  • 2013-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多