我每天都面临着在我的项目中非常令人沮丧的ConstraintLayout问题。
项目gradle文件:
buildscript {
ext.support_library_version = '27.0.2'
ext.play_services_version = '11.6.2'
ext.firebase_version = '11.6.2'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'io.realm:realm-gradle-plugin:4.2.0'
classpath 'com.google.gms:google-services:3.1.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
maven { url "https://maven.google.com" }
maven { url 'https://jitpack.io' }
}
}
这是我的app gradle的简短版本:
apply plugin: 'com.android.library'
apply plugin: 'realm-android'
// set to 'cmake', 'none'
def nativeBuildSystem = 'none'//'cmake'
realm {
syncEnabled = false
}
android {
defaultConfig {
targetSdkVersion 27
compileSdkVersion 27
minSdkVersion 21
// for using vectors for less than 21 API
vectorDrawables.useSupportLibrary = true
versionCode 56
dexOptions {
preDexLibraries true
javaMaxHeapSize "4g"
}
// Enabling multidex support.
multiDexEnabled true
versionName "1.6.5"
renderscriptTargetApi 2
renderscriptSupportModeEnabled true // Enable RS support
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
configurations {
all*.exclude group: 'commons-logging', module: 'commons-logging'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
/********************************* Deep Linking Library *********************************************/
api 'com.airbnb:deeplinkdispatch:3.1.1'
annotationProcessor 'com.airbnb:deeplinkdispatch-processor:3.1.1'
/********************************* Android SDK *********************************************/
api "com.android.support:appcompat-v7:$support_library_version"
api 'com.android.support.constraint:constraint-layout:1.0.2'
api "com.android.support:percent:$support_library_version"
api "com.android.support:recyclerview-v7:$support_library_version"
api "com.android.support:gridlayout-v7:$support_library_version"
api "com.android.support:cardview-v7:$support_library_version"
api "com.android.support:design:$support_library_version"
api "com.android.support:support-vector-drawable:$support_library_version"
api "com.android.support:support-core-utils:$support_library_version"
api 'com.android.support:multidex:1.0.2'
}
我在布局编辑器中看到的内容:
在我的xml下面:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>
在这种情况下,布局编辑器说:
如果我点击显示例外,我会看到:
java.lang.NegativeArraySizeException
at android.support.constraint.R$styleable.<clinit>(Unknown Source)
at android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:440)
at android.support.constraint.ConstraintLayout.<init>(ConstraintLayout.java:420)
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:211)
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:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
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)
为了解决问题我尝试了很多但没有成功。我没有解决使用简单的方法,如无效缓存/清理项目/重建项目等...
答案 0 :(得分:1)
<强>问题:强>
如果您在 attr.xml 中定义的一个<declare-stylable>
标记中包含太多属性,布局编辑器似乎会遇到一些麻烦!
<强>解决方案:强>
我在一个<declare-stylable>
代码中有 49 属性
如果我删除 4 属性,那么我 45 ,布局编辑器正在运行。
我还在Google Issue Tracker上添加了一个问题:
https://issuetracker.google.com/issues/71641021
Google问题更新
这已针对Android Studio 3.1版本进行了修复。
答案 1 :(得分:0)
请勿使用"use strict";
var db = require('./db');
exports.handler = (event, context, callback) => {
db.connect(function (conn) {
if (conn == null) {
console.log("Database connection failed: ");
callback("Error", "Database connection failed");
} else {
console.log('Connected to database.');
conn.query("INSERT INTO employee(name,salary) VALUE(?,?)",['Joe',8000], function(err,res){
if(err) throw err;
else {
console.log('A new employee has been added.');
}
});
db.getConnection().end();
callback(null, "Database connection done");
}
});
};
,而应使用ConstraintLayout
或Relative...
。这应该有用。
Linear...