问题
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