我尝试从源代码添加Android库,如接受的答案所示:
Adding Library Source into Android Studio
我在build.gradle文件中收到错误:
错误:(4,0)无法为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler类型的对象获取未知属性'supportLibVersion'。
这是我的build.gradle文件:
public class SplashActivity extends Activity {
private static final String TAG = "SplashActivity";
private static final boolean DO_XML = false;
private ViewGroup mMainView;
private SplashView mSplashView;
private View mContentView;
private Handler mHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// change the DO_XML variable to switch between code and xml
if(DO_XML==true){
// inflate the view from XML and then get a reference to it
} else {
Log.d("Main","end now");
// create the main view and it will handle the rest
mMainView = new MainView(getApplicationContext());
mSplashView = ((MainView) mMainView).getSplashView();
setContentView(mMainView);
}
// pretend like we are loading data
startLoadingData();
}
private void startLoadingData(){
// finish "loading data" in a random time between 1 and 3 seconds
Random random = new Random();
mHandler.postDelayed(new Runnable(){
@Override
public void run(){
onLoadingDataEnded();
}
}, 1000 + random.nextInt(2000));
}
private void onLoadingDataEnded(){
// now that our data is loaded we can initialize the content view
// add the content view to the background
Context context = getApplicationContext();
// add the content view to the background
mSplashView.splashAndDisappear(new ISplashListener(){
@Override
public void onStart(){
// log the animation start event
if(BuildConfig.DEBUG){
Log.d(TAG, "splash started");
}
}
@Override
public void onUpdate(float completionFraction){
// log animation update events
if(BuildConfig.DEBUG){
Log.d(TAG, "splash at " + String.format("%.2f", (completionFraction * 100)) + "%");
}
}
@Override
public void onEnd(){
// log the animation end event
if(BuildConfig.DEBUG){
Log.d(TAG, "splash ended");
}
// free the view so that it turns into garbage
mSplashView = null;
if(!DO_XML){
// if inflating from code we will also have to free the reference in MainView as well
// otherwise we will leak the View, this could be done better but so far it will suffice
((MainView) mMainView).unsetSplashView();
}
}
});
}
}
我可以看到该库有一个名为dependencies.gradle的文件,其中包含以下内容:
apply plugin: 'com.android.library'
dependencies {
compile "com.android.support:support-annotations:${supportLibVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.okhttp3
compile rootProject.ext.dep.lost
...
看来这是定义属性的地方,但我认为在构建过程中没有看到它。 dependencies.gradle比build.gradle文件高一级,这可以解释为什么在导入Gradle项目后看不到该属性。可以在以下位置找到原始库源:
解决此问题的最佳方法是什么?
由于
米奇