我正在将所有支持/ appcompat库迁移到androidx.在所有更新之后,由于此错误,我无法构建我的项目
:app:processDebugManifest UP-TO-DATE
AGPBI: {"kind":"error","text":"error: resource android:attr/fontVariationSettings not found.","sources":[{"file":"/Users/xxx/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/7cae290a69b05f5ffc25283e26a7eb4a/res/values/values.xml","position":{"startLine":250,"startColumn":4,"startOffset":27058,"endColumn":68,"endOffset":27122}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/ttcIndex not found.","sources":[{"file":"/Users/xxx/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/7cae290a69b05f5ffc25283e26a7eb4a/res/values/values.xml","position":{"startLine":250,"startColumn":4,"startOffset":27058,"endColumn":68,"endOffset":27122}}],"original":"","tool":"AAPT"}
:app:processDebugResources
Run Code Online (Sandbox Code Playgroud)
我试图逐个包含所有依赖项,以确定导致问题的原因.只有当我删除Room库¯\ _(ツ)_ /¯时才能构建
https://developer.android.com/topic/libraries/architecture/adding-components#room
这很奇怪,因为问题似乎来自造型资源,但房间只是一个数据库库.
有没有人有任何想法或解决方案,包括房间而不打破一切?
===============================
我的conf:
compileSdkVersion 27
buildToolsVersion 27.0.3
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
}
dependencies {
// ROOM
implementation ('androidx.room:room-runtime:' + androidxRoomVersion)
implementation ('androidx.room:room-rxjava2:' + androidxRoomVersion)
implementation ('androidx.room:room-guava:' + androidxRoomVersion)
kapt ('androidx.room:room-compiler:' + androidxRoomVersion)
}
Run Code Online (Sandbox Code Playgroud)
with:androidxRoomVersion = 2.0.0-alpha1
android android-support-library android-gradle-plugin android-room androidx
我的应用程序在Android 4.3到Android 9 Pie之前都可以正常工作,但是我的应用程序无法在Android 10(Q API 29)上运行并崩溃。这是我的日志-为什么会这样?
java.lang.RuntimeException: Unable to start activity
ComponentInfo{ir.mahdi.circulars/ir.mahdi.circulars.MainActivity}:
android.view.InflateException: Binary XML file line #17
in ir.mahdi.circulars:layout/abc_screen_simple: Binary XML file line #17
in ir.mahdi.circulars:layout/abc_screen_simple:
Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout
Run Code Online (Sandbox Code Playgroud)
这是我的mainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:layoutDirection="ltr"
tools:context=".MainActivity">
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
更新
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
} }
dependencies {
implementation …Run Code Online (Sandbox Code Playgroud) 我决定使用来自 AndroidX 安全库的新 EncryptedSharedPreferences。由于该应用程序支持 API 21 及更高版本,我决定试用这个新的 v1.1.0-alpha02 版本,因为它支持 API 21+
因此,我成功实现了 API 23+,但对于不支持 Android KeyStore 的旧版本,我无法正确实现,并且没有确切的说明应该如何创建主密钥以使其以某种方式工作.
初始化 SharedPrefs 的代码:
EncryptedSharedPreferences.create(
"prefs_name",
createMasterKey(),
App.appContext,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
Run Code Online (Sandbox Code Playgroud)
使用此功能创建主密钥
private fun createMasterKey(): String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
} else {
val alias = "my_alias"
val start: Calendar = GregorianCalendar()
val end: Calendar = GregorianCalendar()
end.add(Calendar.YEAR, 30)
val spec = KeyPairGeneratorSpec.Builder(App.appContext)
.setAlias(alias)
.setSubject(X500Principal("CN=$alias"))
.setSerialNumber(BigInteger.valueOf(abs(alias.hashCode()).toLong()))
.setStartDate(start.time).setEndDate(end.time)
.build()
val kpGenerator: KeyPairGenerator = KeyPairGenerator.getInstance(
"RSA",
"AndroidKeyStore"
)
kpGenerator.initialize(spec)
val kp: KeyPair …Run Code Online (Sandbox Code Playgroud) 迁移到AndroidX后一直面临此错误.
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type: ErrorScope{Error scope for class <ERROR CLASS> with arguments: org.jetbrains.kotlin.types.IndexedParametersSubstitution@14ac19e7}
Run Code Online (Sandbox Code Playgroud)
这个链接没有多大帮助
我知道有办法改变ViewPager编程幻灯片的动画持续时间(这里)。
但它不工作 ViewPager2
我试过这个:
try {
final Field scrollerField = ViewPager2.class.getDeclaredField("mScroller");
scrollerField.setAccessible(true);
final ResizeViewPagerScroller scroller = new ResizeViewPagerScroller(getContext());
scrollerField.set(mViewPager, scroller);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
IDE 给我关于“mScroller”的警告:
无法解析字段“mScroller”
如果我们运行此代码将无法工作并在下面给我们错误:
No field mScroller in class Landroidx/viewpager2/widget/ViewPager2; (declaration of 'androidx.viewpager2.widget.ViewPager2' appears in /data/app/{packagename}-RWJhF9Gydojax8zFyFwFXg==/base.apk)
Run Code Online (Sandbox Code Playgroud)
那么我们如何才能实现这个功能呢?
有什么方法可以读取依赖于 buildType 的常量${deepLinkHost}?
debug -> deepLinkUri = http://link.debug/
staging -> deepLinkUri = http://link.staging/
release -> deepLinkUri= http://link/
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation_home"
app:startDestination="@id/fragment_home">
<fragment
android:id="@+id/fragment_home"
android:name="..."
tools:layout="@layout/fragment_home">
<argument
android:name="token"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
<deepLink app:uri="${deepLinkUri}/?code={token}" />
</fragment>
Run Code Online (Sandbox Code Playgroud)
这是之前通过 build.gradle 上的 manifestPlaceholders.deepLinkHost 和 AndroidManifest 中的活动深度链接来管理的,但是一旦 google 使用 1 Activity to N Fragments,我们如何使用导航组件来管理它?
我一直在尝试迁移我的应用程序以使用androidx,但是我似乎遇到了一个奇怪的错误。从我在调用AppCompatActivity时进行扩展的活动中getLifeCycle()引发以下异常
Caused by: java.lang.NoSuchMethodError: No super method getLifecycle()Landroidx/lifecycle/Lifecycle; in class Landroidx/core/app/ComponentActivity; or its super classes
at androidx.fragment.app.FragmentActivity.getLifecycle(FragmentActivity.java:324)
Run Code Online (Sandbox Code Playgroud)
我认为AppCompatActivity应该实现LifecycleOwner,但不是。难道我做错了什么?这是我的gradle依赖
implementation files("libs/jsoup-1.8.3.jar")
implementation "com.github.philjay:MPAndroidChart:v3.0.2"
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation "androidx.constraintlayout:constraintlayout:2.0.0-alpha2"
implementation 'androidx.constraintlayout:constraintlayout-solver:2.0.0-alpha2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0" // use kapt for Kotlin
implementation "de.hdodenhof:circleimageview:2.2.0"
implementation 'androidx.core:core:1.1.0-alpha01'
implementation "com.thoughtbot:expandablerecyclerview:1.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.0.0"
implementation "androidx.lifecycle:lifecycle-viewmodel:2.0.0"
implementation "com.github.franmontiel:FullScreenDialog:1.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.github.apl-devs:appintro:v4.2.3"
implementation "com.google.firebase:firebase-crash:16.2.1"
implementation "com.google.firebase:firebase-core:16.0.5"
Run Code Online (Sandbox Code Playgroud) 我一直在尝试将AndroidX集成到我的混合React Native项目中,我遇到了Jetifier不在"本地"项目上运行的问题.这导致我的所有React Native库仍然使用旧的支持库.我已将相应的行放入gradle.properties文件中:
android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)
这适用于任何远程库,但React Native将其所有库作为本地模块放在磁盘上.
我已经尝试了很多东西,但到目前为止,我最好的解决方案是一个post-package脚本,基本上手动替换所有的包,并将库添加/删除到各种gradle脚本.
这是一个非常手动的过程,并不是超级可持续的.有没有更好的方法来处理这个问题?
android react-native react-native-android androidx android-jetifier
今天,我将Android Studio更新为3.5。更新后,我在尝试运行该应用程序时发现以下警告。
规则-keep公共类*扩展了androidx.versionedparcelable.VersionedParcelable {(); }使用扩展,但实际上与工具匹配。
我知道警告与我的保卫规则有关。因此,我仔细检查了我的proguard规则文件,但是我确定没有添加该规则,并且不在我的proguard规则文件中。
下面是我构建项目时的警告。
我的项目正在使用AndroidX。任何人都可以知道可以跳过警告或警告来自何处吗?任何想法或替代方式将不胜感激。
我想将com.google.android.material.tabs.TabLayout组件与Android的新ViewPager实现一起使用androidx.viewpager2.widget.ViewPager2。但是,setupWithViewPager(..)提供的方法TabLayout仅支持旧的ViewPager实现。有没有一种方法可以轻松地将a绑定TabLayout到ViewPager2组件?
android ×10
androidx ×10
android-10.0 ×1
android-room ×1
calligraphy ×1
deeplink ×1
encrypted-shared-preference ×1
kotlin ×1
proguard ×1
react-native ×1
security ×1