gpt4 book ai didi

Android库正确使用V4支持库混淆

转载 作者:行者123 更新时间:2023-12-03 04:45:41 24 4
gpt4 key购买 nike

我正在尝试减少我的项目的 apk 大小,为此我正在尝试删除整个 support-v4 库依赖项,而只添加我的项目所需的模块。根据下面,似乎可以只包含我需要的模块,而不是导入整个 support-v4 库(1)。我当前的项目是在 gradle 中使用 support-v4(整个库)。每当我使用时,在导入 header 上的 ActivityCompat 等 Activity 类中,我会看到:“import android.support.v4.app.ActivityCompat;”。我的困惑是我已经从 gradle 中删除了 support-v4 库,并且只包括了 ActivityCompat 类所需的模块,即:“com.android.support:support-compat:27.0.0”。为什么当我尝试使用 ActivityCompat 类时它仍然导入相同的“import android.support.v4.app.ActivityCompat;”?这是预期的吗?

来自Android引用:
https://developer.android.com/reference/android/support/v4/app/ActivityCompat.html

(1)"Note: Prior to Support Library revision 24.2.0, there was a single v4 support library. That library was divided into multiple modules to improve efficiency. For backwards compatibility, if you list support-v4 in your Gradle script, your APK will include all of the v4 modules. However, to reduce APK size, we recommend that you just list the specific modules your app needs."


import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;<--regardless of whether I include support-v4 or only the module needed from android(com.android.support:support-compat:27.0.0) same import is still being used.
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);
}
}

最佳答案

根据 ActivityCompat documentation (具体来说,在右上角):

belongs to Maven artifact com.android.support:support-compat:27.0.0



所以你使用的类在 support-compat依赖,正如预期的那样。依赖项的命名仅与类所在的包的命名松散相关(显然,更改类的包会破坏每个升级的人,这可能并不理想)。

关于Android库正确使用V4支持库混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48482268/

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