一开始界面中是这样的,v7包已正确导入且build顺利完成,但是有关v7包的所有语句诸如AppCompatActivity,AleartDialogue都标红了。但是很奇怪的是,同样的gradle,如果我新建一个app却又能正常显示v7包的语法。
经过几番周折,最后我找到,尽管均已导入v7包,但是新建的程序的build.gradle里还多了下面几条中已标红的两条或三条:
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
并且新建程序的Project下的External Library中比原程序多了许多Gradle files,顺着这些files的路径我明白了这些files是由implementation控制导入的。如图(上图为报错程序,下图为修改后的程序,可以发现多了许多文件。)
后来我尝试在Dependencies里加入缺失的Library Dependencies,结果发现加入后External Library比原来的多了许多文件,但仍然无法识别v7包的语法。
最后,正解就是把所有Library Dependencies删掉,也就是带有m
图标的所有依赖项删掉,Clean Build一次,再把上文提及的五
条implementation在dependencies中加回进去,这样就成功
了。
小记一波,百度并非样样都有,我耗费了一天才找到正解,小记一波供日后参考。