标签: androidx

Androidx模块,未找到android:attr/ttcIndex和android:attr/fontVariationSettings

我正在将所有支持/ 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

21
推荐指数
2
解决办法
2万
查看次数

在Android 10上崩溃(layout / abc_screen_simple第17行中的InflateException)

我的应用程序在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)

android calligraphy androidx android-10.0

21
推荐指数
5
解决办法
2121
查看次数

AndroidX 安全 EncryptedSharedPreferences v1.1.0 /w API 21 问题

我决定使用来自 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)

security android androidx encrypted-shared-preference

21
推荐指数
4
解决办法
4471
查看次数

java.lang.IllegalStateException:不应为错误类型创建SimpleTypeImpl

迁移到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)

这个链接没有多大帮助

android kotlin android-studio-3.2 androidx

20
推荐指数
3
解决办法
2652
查看次数

以编程方式滑动时更改 ViewPager2 滚动速度

我知道有办法改变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)

那么我们如何才能实现这个功能呢?

android androidx android-viewpager2

20
推荐指数
2
解决办法
6729
查看次数

导航组件:使用 uri 依赖于 buildType 的 Deeplink

有什么方法可以读取依赖于 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,我们如何使用导航组件来管理它?

android deeplink androidx

20
推荐指数
1
解决办法
7482
查看次数

迁移到androidx后,没有超级方法getLifecycle()

我一直在尝试迁移我的应用程序以使用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)

android android-lifecycle androidx

19
推荐指数
3
解决办法
5209
查看次数

使用AndroidX和React Native的问题

我一直在尝试将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

19
推荐指数
1
解决办法
1万
查看次数

android studio 3.5警告:规则-keep public class *扩展了androidx.versionedparcelable.VersionedParcelable {&lt;init&gt;(); }`的使用

今天,我将Android Studio更新为3.5。更新后,我在尝试运行该应用程序时发现以下警告。

规则-keep公共类*扩展了androidx.versionedparcelable.VersionedParcelable {(); }使用扩展,但实际上与工具匹配。

我知道警告与我的保卫规则有关。因此,我仔细检查了我的proguard规则文件,但是我确定没有添加该规则,并且不在我的proguard规则文件中。

我的Progurad文件

下面是我构建项目时的警告。

在此处输入图片说明

我的项目正在使用AndroidX。任何人都可以知道可以跳过警告或警告来自何处吗?任何想法或替代方式将不胜感激。

android proguard android-studio androidx

19
推荐指数
1
解决办法
3573
查看次数

如何在Android中将TabLayout与ViewPager2一起使用

我想将com.google.android.material.tabs.TabLayout组件与Android的新ViewPager实现一起使用androidx.viewpager2.widget.ViewPager2。但是,setupWithViewPager(..)提供的方法TabLayout仅支持旧的ViewPager实现。有没有一种方法可以轻松地将a绑定TabLayoutViewPager2组件?

android android-tablayout androidx android-viewpager2

18
推荐指数
7
解决办法
6100
查看次数