Android studio, import class disappear from gradle file

一笑奈何 提交于 2019-12-11 07:16:24

问题


This is a little weird, I have a gradle.build file:

apply plugin: 'com.android.application'

android {
    apply from: '../dev-tools/gradle/common-cyborg-app.gradle'

    defaultConfig {
        applicationId "com.nu.art.cyborg.demo"
    }

    defineDefaultVariantsAPK("dev-project")
}

when I add the following import:

import com.android.build.OutputFile

the import just disappears.. really there is no other way to describe it. I've cleared caches and restarted, cleaned the project and nothing.

Every time I paste the line, after a few seconds it is "magically" gone...

Anyone?


Update so the accepted answer worked for a while (a day) and once studio crashed, it stopped working... I really don't know why and I wasted too much time on it that I don't really care, BUT I did manage to workaround the problem, take a look, I pass the filter from the app build.gradle file


回答1:


Android Studio will remove unussed imports from your gradle files. When you paste it in you are not ussing that import so it removes it. Yea I know, it is silly.

What you should do is first use the class with fully classified name and then add import later.



来源:https://stackoverflow.com/questions/47859821/android-studio-import-class-disappear-from-gradle-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!