对于我正在使用的仪器测试
@RunWith(AndroidJUnit4.class)
Run Code Online (Sandbox Code Playgroud)
从
import androidx.test.runner.AndroidJUnit4;
Run Code Online (Sandbox Code Playgroud)
为了建立我的测试用例.现在,这条线被标记为与提示使用过时AndroidJUnit4的
import androidx.test.ext.junit.runners.AndroidJUnit4
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试AndroidJUnit4从命名包导入我得到错误,ext无法解决.
您是否有任何想法,应该在gradle中包含哪些包来解决此问题?
我正在阅读关于Android的房间库.我看到他们改变包装android来androidx.我不明白.请有人解释一下.
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)
即使这也适用于android包装.
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)
androidx而不是android.android android-architecture-components android-jetpack androidx
如何从XML 设置RecyclerView layoutManager?
<android.support.v7.widget.RecyclerView
app:layoutManager="???"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud) 我正在使用Android Studio 3.2 Beta5将我的项目迁移到AndroidX.当我重建我的应用程序时,我遇到了这些错误:
错误:[TAG]无法解析变量'$ {animal.sniffer.version}'
错误:[TAG]无法解析变量'$ {junit.version}'
完全清洁和重建不起作用!有人知道怎么修这个东西吗?请帮我.
gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Run Code Online (Sandbox Code Playgroud)
的build.gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-beta05'
classpath 'com.google.gms:google-services:4.0.1'
classpath "io.realm:realm-gradle-plugin:5.3.1"
classpath 'io.fabric.tools:gradle:1.25.4'
classpath 'com.google.firebase:firebase-plugins:1.1.5'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
应用程序/的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric' …Run Code Online (Sandbox Code Playgroud) android android-studio android-studio-3.0 android-studio-3.2 androidx
什么是Jetifier?例如,要使用androidx打包的依赖项创建一个新项目,这个新项目需要将以下行添加到gradle.properties文件中:
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)
那是什么意思 - "启用jetifier"?
在一个新创建的Androidx项目中:appcompat:appcompat:1.0.0-rc01,我得到了
java.lang.ClassNotFoundException: Didn't find class
"android.view.View$OnUnhandledKeyEventListener" on path: DexPathList
Run Code Online (Sandbox Code Playgroud)
我还添加了configuration.all
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "androidx.appcompat") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "1.+"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个不会影响应用程序功能或崩溃.但是,当应用程序运行时,它总是会出现此错误.请帮我解决错误.整个堆栈跟踪如下.
I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
I/art: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2)
at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430)
at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:645)
at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) …Run Code Online (Sandbox Code Playgroud) 我刚刚通过Android Studio菜单选项迁移到androidx __CODE__
我收到以下错误:
android.view.InflateException:二进制XML文件行#2:二进制XML文件行#2:错误膨胀类androidx.constraintlayout.ConstraintLayout
任何的想法?
堆栈跟踪:
2018-10-19 00:25:58.128 28131-28131/com.midounoo.midounoo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.midounoo.midounoo, PID: 28131
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.midounoo.midounoo/com.midounoo.midounoo.Base.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6255)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
Caused by: android.view.InflateException: …Run Code Online (Sandbox Code Playgroud) 我正在使用BottomSheetBehavior原始支持库:
implementation 'com.android.support:design:27.1.1'
Run Code Online (Sandbox Code Playgroud)
当我迁移使用新androidx库时虽然BottomSheetBehavior缺少了.上述支持库的映射也不在AndroidX重构列表中,但迁移工具将其删除.
我错过了将BottomSheetBehavior包含在新androidx库中.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// ReactiveX
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'com.android.support:design:28.1.0'
// Android Compatability Libraries
// Version: https://developer.android.com/topic/libraries/support-library/refactor
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
// Android Navigation Component
// Check here for updated version info - will move to androidx soon.
// https://developer.android.com/topic/libraries/architecture/adding-components
def nav_version = "1.0.0-alpha04"
// use -ktx for Kotlin
implementation …Run Code Online (Sandbox Code Playgroud) 我升级了android studio to 3.4 canary,现在由于以下错误我无法再成功构建:
The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.
Run Code Online (Sandbox Code Playgroud)
更多细节:
Caused by: java.lang.RuntimeException: Failed to transform '.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/9.0.0-SNAPSHOT/732f93940c74cf32a7c5ddcc5ef66e53be052352/butterknife-compiler-9.0.0-SNAPSHOT.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated …Run Code Online (Sandbox Code Playgroud) 我试图使用此代码片段获取Snackbar的Textview:
snackbarView.findViewById<TextView>(android.support.design.R.id.snackbar_text)
Run Code Online (Sandbox Code Playgroud)
但Android Studio无法解析设计库.
如何才能使此代码生效?
android textview android-support-library android-snackbar androidx
androidx ×10
android ×9
android-architecture-components ×1
bottom-sheet ×1
butterknife ×1
gradle ×1
junit ×1
textview ×1
xml ×1