如果已经包含support-v4
,是否需要在gradle中加入appcompat-v7
和support-design
?我知道,当包括support-design support-v4
和appcompat-v7
已经是我的外部库的一部分时,即使它们不在gradle中也是如此。我知道support-design
取决于appcompat-v7
而appcompat-v7
取决于support-v4
我只是想知道从gradle中移除support-v4
和appcompat-v7
是否会导致任何问题。
我还要排除support-v4
(以减少apk尺寸),我是通过将其从support-design
中排除并仅添加support-v4
所需的模块来完成的,我是在正确的方向?见下文:
的gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.test.applicationtest_v4lib"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile('com.android.support:design:26.0.1'){
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.android.support:support-fragment:26.0.1'
//compile 'com.android.support:support-compat:26.0.1'
//compile 'com.android.support:support-v4:26.0.1'
testCompile 'junit:junit:4.12'
}
我的活动:
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
//import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
//ActivityCompat
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
Android支持库套件中的大多数库都依赖于一个或多个库。例如,几乎所有支持库都依赖于support-compat包。通常,您不必担心支持库依赖项,因为gradle构建工具通过自动包含依赖库来管理库依赖项。
如果要查看应用程序中包含的库和库依赖项,请在应用程序开发项目的构建根目录中运行以下命令,以获取该项目的依赖项报告,包括Android支持库和其他库:
gradle -q依赖项your-app-project:dependencies