Android Studio problem with compiling “The process cannot access the file because it is being used by another process.”

前端 未结 2 1093
迷失自我
迷失自我 2021-01-13 12:33

I know this question has been asked before, but there wasn\'t a satisfactory answer, and the last post was three years ago. I am using android studio 3.6.2 in windows 10. Ev

相关标签:
2条回答
  • 2021-01-13 13:18

    [Remove Build][Go to Edit Configurations]

    Go to Edit Configurations check that you are not building before each launch. Remove "Build"

    0 讨论(0)
  • 2021-01-13 13:22

    I also encountered the same problem in Android Studio 4.x in Windows 10. Simply using "Restart and Invalidate" does not work for me. Sometimes, deleting the build folder will work but I cannot build the project more than once. Here is my solution:

    Check Java Runtime Version Used by Gradle and System Default

    Having multiple daemons may cause problems as described in documentation from Gradle. To solve this problem,

    1. Open your project in Android Studio
    2. Find the JDK location used in your project (File > Project Structure > SDK Location > JDK Location)
    3. Open a command prompt. Let $ANDROID_JDK be the path you found in Step 2. Type $ANDROID_JDK/bin/java.exe --version to find out the Java version.
    4. Type java.exe --version to find out the default Java version used by the system.
    5. Compare if the version information from Step 3 and Step 4 are the same.

    Build with app Configuration

    Empty Composable Activity template will create two build configurations. You should change the build configuration to app as shown in the figure below. This solves my problem.

    build configuration

    Proper Launching Procedure

    As illustrated in Bilal Aslam's solution, we can edit the build configurations (Run > Edit Configurations). After selecting Compose Preview > Default Preview, you will see Build then Gradle-aware Make in the Before launch panel. Remove Build should be able to solve the problem. The side-effects are unclear.

    0 讨论(0)
提交回复
热议问题