就是因為你的android工程是lib類型的
如:
apply plugin: 'com.android.library' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
這樣你在R.id.xxx 取R中變量的時候並非是final類型,所以只能老老實實findviewbyid了!!!
***當然想要把R中變量改為final也是可行的,可能需要在打包的過程中利用腳本把Libray的R中字段替換;有興趣的可以研究下哦!
