在编辑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$3(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)
清理/构建/使缓存等无效等没有帮助。请注意,该应用程序运行正常,它只是不再有效的UI编辑器。 谁面临同样的问题,或者有解决方案?
答案 0 :(得分:21)
支持库26.0.0-beta2存在问题 - 您需要切换回测试版1才能在Android Studio中运行。