我目前使用以下lib
的约束布局 implementation 'com.android.support.constraint:constraint-layout:1.0.2'
通过android studio中的更新警告,我将其更新为
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
之后每当我尝试构建或运行项目时,我都会遇到以下问题(请参阅堆栈跟踪)
java.lang.AssertionError: TOP
at android.support.constraint.solver.widgets.Guideline.getAnchor(Guideline.java:159)
at android.support.constraint.solver.widgets.ConstraintWidget.immediateConnect(ConstraintWidget.java:1579)
at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:1012)
at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:793)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1540)
at android.view.View.measure(View.java:18804)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18804)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18804)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18804)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2112)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1228)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1464)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
还遇到了崩溃问题,
E/CrashlyticsCore: Failed to execute task.
java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:177)
at com.crashlytics.android.core.CrashlyticsBackgroundWorker.submitAndWait(CrashlyticsBackgroundWorker.java:41)
at com.crashlytics.android.core.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:320)
at com.crashlytics.android.core.CrashlyticsController$6.onUncaughtException(CrashlyticsController.java:300)
at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:42)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
如果我恢复到1.0.2版本工作正常。这是一个注意到的错误或不?如何解决这个问题?
答案 0 :(得分:5)
我们遇到了同样的问题,问题是新版本正在添加一些额外的断言,因此旧代码可能会停止工作,因为约束布局的工作方式,堆栈跟踪根本不直观。
public ConstraintAnchor getAnchor(Type anchorType) {
switch(anchorType) {
case LEFT:
case RIGHT:
if (this.mOrientation == 1) {
return this.mAnchor;
}
break;
case TOP:
case BOTTOM:
if (this.mOrientation == 0) {
return this.mAnchor;
}
break;
case BASELINE:
case CENTER:
case CENTER_X:
case CENTER_Y:
case NONE:
return null;
}
throw new AssertionError(anchorType.name());
}
这是导致异常的方法。检查的是,如果指南是垂直指南,任何为其添加约束的项目都应该横向(开始或结束),反之则为垂直指南。
在我们的例子中,我们使用
进行了布局app:layout_constraintTop_toBottomOf="@+id/guideline"
app:layout_constraintStart_toStartOf="@+id/guideline"
检查布局并确保在指南中添加适当的约束。
答案 1 :(得分:2)
只需将android:orientation =“ horizontal”或android:orientation =“ vertical”添加到您的准则