gpt4 book ai didi

java - 为什么我仍然可以使用 support-v4 库而不在 gradle 上导入它?

转载 作者:行者123 更新时间:2023-12-03 06:32:23 24 4
gpt4 key购买 nike

我很困惑,在我的 gradle 中我没有导入 support-v4,但我似乎能够使用该库,support-v4 默认包含为依赖项吗?见下文?同样在我的项目文件夹中,每次创建项目和各个模块时,我都可以看到 jars 支持 v4?

项目等级:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我的应用程序:
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.ok.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'
testCompile 'junit:junit:4.12'
}

-activity 下面可以导入 support-v4 而无需在 gradle 中导入 support-v4:
package com.example.ok.applicationtest_v4lib;

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.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();
}
});
//I am able to use below class yet I have not imported v4 library.
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);
}
}

最佳答案

如果您有 appcompat-v7 , 你有 appcompat-v4 .

运行./gradlew app:dependencies你会看到

+--- com.android.support:appcompat-v7:25.4.0
| +--- com.android.support:support-annotations:25.4.0
| +--- com.android.support:support-v4:25.4.0 (*)
| +--- com.android.support:support-vector-drawable:25.4.0
| | +--- com.android.support:support-annotations:25.4.0
| | \--- com.android.support:support-compat:25.4.0 (*)
| \--- com.android.support:animated-vector-drawable:25.4.0
| +--- com.android.support:support-vector-drawable:25.4.0 (*)
| \--- com.android.support:support-core-ui:25.4.0 (*)

关于java - 为什么我仍然可以使用 support-v4 库而不在 gradle 上导入它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48482792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com