我在我的 Android 项目中使用了 svg 文件。Android 4.4 或更低版本存在问题。我已经尝试过这些解决方案
app:srcCompat,vectorDrawables.useSupportLibrary = true 在 gradle 文件和 AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);在BaseActivity.svg android android-support-library android-5.0-lollipop android-vectordrawable
我已经阅读了几篇文章和文档以及SO问题,以了解minSDK与targetSDK和compileSDK之间的区别.
例如,在Medium上:选择compileSdkVersion,minSdkVersion和targetSdkVersion
这基本上总结了一下
minSdkVersion <= targetSdkVersion <= compileSdkVersion
但是仍然想了解如果我设置TargetSDK = 22但Compile SDK = 26有什么优缺点?
需要考虑的要点是 -
android android-support-library android-min-sdk runtime-permissions android-architecture-components
摇篮:
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Run Code Online (Sandbox Code Playgroud)
=========================
ext {
support_version = '27.0.2'
dagger_version = '2.14.1'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
//support
implementation "com.android.support:appcompat-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//rx
implementation 'io.reactivex.rxjava2:rxjava:2.1.8'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
//test
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//Dagger 2
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
provided 'org.glassfish:javax.annotation:10.0-b28'
}
Run Code Online (Sandbox Code Playgroud)
它对我很有用,但是如果我启用了DataBinding:
dataBinding {
enabled = true
}
Run Code Online (Sandbox Code Playgroud)
我收到了警告com.android.support:appcompat-v7:
所有com.android.support库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃).找到的版本27.0.2,21.0.3.示例包括com.android.support:animated-vector-drawable:27.0.2和com.android.support:support-v4:21.0.3 more ...(Ctrl + F1)
在ContextCompat中丢失方法checkSelfPermission:
ContextCompat.checkSelfPermission(context, android.Manifest.permission.READ_SMS) …Run Code Online (Sandbox Code Playgroud) 由于我将我的应用程序迁移到 androidx,因此当我启动任务组合时,Jenkins 出现错误。这是错误:
Program type already present:
android.support.v4.app.INotificationSideChannel$Stub$Proxy
Run Code Online (Sandbox Code Playgroud)
但是我在 Android Studio 上没有这个错误,我可以毫无问题地构建 apk。
因此,我尝试从 google play 服务中排除 support-v4 模块:
implementation( "com.google.android.gms:play-services-maps:16.0.0"){
exclude module: 'support-v4'
}
implementation ("com.google.android.gms:play-services-location:16.0.0"){
exclude module: 'support-v4'
}
implementation ("com.google.android.gms:play-services-places:16.0.0"){
exclude module: 'support-v4'
}
Run Code Online (Sandbox Code Playgroud)
然后生成apk,但在启动应用程序时出现此错误:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArraySet;
at com.google.android.gms.common.api.internal.c.<init>(Unknown Source:45)
at com.google.android.gms.common.api.internal.c.a(Unknown Source:33)
at com.google.android.gms.common.api.e.<init>(Unknown Source:51)
at com.google.android.gms.common.api.e.<init>(Unknown Source:13)
at com.google.android.gms.location.b.<init>(Unknown Source:8)
at com.google.android.gms.location.f.a(Unknown Source:2)
Run Code Online (Sandbox Code Playgroud)
但是再一次,在 Android Studio 上一切正常,自从迁移到 Androidx 以来,问题只出现在 Jenkins 上。
谢谢你的帮助
我将我的课程从 Activity 更改为 AppCompatActivity。
并item.getActionView() 改为 MenuItemCompat.getActionView(item)
现在我在下面的代码中得到NPE。
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.messages, menu);
MenuItem item = menu.findItem(R.id.menuTxtSize);
Spinner spinner = (Spinner) MenuItemCompat.getActionView(item);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
int index = sp.getInt(getString(R.string.pr_text_size),
Integer.parseInt(getString(R.string.pr_default_text_size)));
spinner.setSelection(index);
E/ACRA: ACRA caught a NullPointerException for com.alex.documentation java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setSelection(int)' on a null object reference at com.alex.message.activities.MessagesActivity
Run Code Online (Sandbox Code Playgroud)
如何修复错误?
android nullpointerexception android-support-library oncreateoptionsmenu
在我使用支持库v7的应用程序中,我想添加一个首选项屏幕.由于Google完全没有提供有关该主题的文档,因此我查找了Stack Overflow上其他地方发现的帖子.
所以这是我的项目:
activity_preferences.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:support="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/toolbar_default"/>
<fragment
android:name=".FragmentPreferences"
name=".FragmentPreferences"
android:tag=".FragmentPreferences"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
ActivityPreferences.java
package com.example.testandroidsupportv7;
import com.example.testandroidsupportv7.R;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class ActivityPreferences extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);
}
}
Run Code Online (Sandbox Code Playgroud)
FragmentPreferences.java
package com.example.testandroidsupportv7;
import com.example.testandroidsupportv7.R;
import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;
public class FragmentPreferences extends PreferenceFragmentCompat
{
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<activity
android:name=".ActivityPreferences"
android:label="@string/app_name"
android:theme="@style/MyTheme.NoActionBar" …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-preferences android-support-library