ConstraintLayout 在 GUI 编辑器中不工作 Android Studio 3.0 - Canary 4
ConstraintLayout not working in GUI editor Android Studio 3.0 - Canary 4
在 Android Studio 3.0 中编辑包含 ConstraintLayout 元素的布局时,我 运行 遇到了问题。
我的依赖如下:
project.ext.support_library_version = '26.0.0-beta2'
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
compile "com.android.support:palette-v7:${project.ext.support_library_version}"
compile "com.android.support:support-v13:${project.ext.support_library_version}"
compile "com.android.support:customtabs:${project.ext.support_library_version}"
compile "com.android.support:cardview-v7:${project.ext.support_library_version}"
...
}
UI 编辑器中显示的错误是:
The following classes could not be instantiated:
- android.support.constraint.ConstraintLayout (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout.
显示的堆栈跟踪如下:
java.lang.AssertionError: Entries for a declare-styleable should be after the array declaration.
at com.android.tools.idea.res.AppResourceRepository.getDeclaredArrayValues(AppResourceRepository.java:634)
at com.android.tools.idea.res.ResourceClassGenerator.generateStyleable(ResourceClassGenerator.java:249)
at com.android.tools.idea.res.ResourceClassGenerator.generate(ResourceClassGenerator.java:120)
at com.android.tools.idea.res.ResourceClassRegistry.findClassDefinition(ResourceClassRegistry.java:102)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:101)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:215)
at android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:494)
at android.support.constraint.ConstraintLayout.<init>(ConstraintLayout.java:466)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:264)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:222)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:206)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:337)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:348)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:248)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:334)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:382)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:591)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate(RenderTask.java:739)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Cleaning/building/invalidate 缓存等没有帮助。请注意,该应用程序运行良好,只是 UI 编辑器不再工作了。
谁遇到同样的问题,或者有解决方案?
支持库 26.0.0-beta2 存在问题 -- 您需要切换回 beta 1 才能在 Android Studio 中运行。
在 Android Studio 3.0 中编辑包含 ConstraintLayout 元素的布局时,我 运行 遇到了问题。
我的依赖如下:
project.ext.support_library_version = '26.0.0-beta2'
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
compile "com.android.support:palette-v7:${project.ext.support_library_version}"
compile "com.android.support:support-v13:${project.ext.support_library_version}"
compile "com.android.support:customtabs:${project.ext.support_library_version}"
compile "com.android.support:cardview-v7:${project.ext.support_library_version}"
...
}
UI 编辑器中显示的错误是:
The following classes could not be instantiated:
- android.support.constraint.ConstraintLayout (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout.
显示的堆栈跟踪如下:
java.lang.AssertionError: Entries for a declare-styleable should be after the array declaration.
at com.android.tools.idea.res.AppResourceRepository.getDeclaredArrayValues(AppResourceRepository.java:634)
at com.android.tools.idea.res.ResourceClassGenerator.generateStyleable(ResourceClassGenerator.java:249)
at com.android.tools.idea.res.ResourceClassGenerator.generate(ResourceClassGenerator.java:120)
at com.android.tools.idea.res.ResourceClassRegistry.findClassDefinition(ResourceClassRegistry.java:102)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:101)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:215)
at android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:494)
at android.support.constraint.ConstraintLayout.<init>(ConstraintLayout.java:466)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:264)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:222)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:206)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:337)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:348)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:248)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:334)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:382)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:591)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate(RenderTask.java:739)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Cleaning/building/invalidate 缓存等没有帮助。请注意,该应用程序运行良好,只是 UI 编辑器不再工作了。 谁遇到同样的问题,或者有解决方案?
支持库 26.0.0-beta2 存在问题 -- 您需要切换回 beta 1 才能在 Android Studio 中运行。