新版AS新增Activity的时候,数据结构是:
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);EdgeToEdge.enable(this);setContentView(R.layout.activity_main3);ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);return insets;});}
}
对于低版本的SDK来说,compileSdk低于34的apk是无法运行的,提示的错误为:
One or more issues found when checking AAR metadata values:The minCompileSdk (34) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-33).
Dependency: androidx.activity:activity:1.8.0.
AAR metadata file: xxx/xxx/xxx.
如果老项目改动大的话,不想进行升级,就删除build.gradle文件中
implementation 'androidx.activity:activity:1.8.0'
这样就可以解决问题了