Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译成功运行失败。。 #7

Closed
quert999 opened this issue May 17, 2017 · 10 comments
Closed

编译成功运行失败。。 #7

quert999 opened this issue May 17, 2017 · 10 comments

Comments

@quert999
Copy link

报错提示
Error:Failed to complete Gradle execution.

Cause:
String index out of range: -1

@quert999
Copy link
Author

翻了一下gradle console,找到以下报错:

Note: there were 11 duplicate class definitions.

e: 错误: Exception while handling step android.databinding.annotationprocessor.ProcessExpressions@2515ecd5 javax.xml.bind.UnmarshalException
e:

e: - with linked exception:
e: [com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。]

@blackbbc
Copy link
Owner

#4

@quert999
Copy link
Author

我在每个build.gradle文件都添加了task,依然报这个错。。

@quert999
Copy link
Author

给dalao递茶,求dalao指导= =。

@blackbbc
Copy link
Owner

blackbbc commented May 17, 2017

那篇博客给出的task方法我没有试过
但是根本解决方法是将所有含有中文的地方都用@string代替

例如

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text='@{"共:" + viewModel.totalCount + "个相关结果"}'
    android:textColor="@color/secondary_text"
    android:textSize="12sp"
    android:visibility="@{viewModel.totalCountVisibility}"
    tools:text="共:274个相关结果" />

在values/strings.xml里加入如下字符串

<string name="gong">共</string>
<string name="jieguo">个相关结果</string>

然后上面的android:text替换成

android:text='@{@string/gone + viewModel.totalCount + @string/jieguo}'

我不这么做的原因有以下几个:

  1. 工作量太大了,所有有中文的地方都要替换
  2. 我主要针对国内用户,不用做多语言支持
  3. 不优雅,破坏了Databinding直观的体验
  4. 我是Linux用户

@quert999
Copy link
Author

我去试试, 拜谢dalao

@guuguo
Copy link

guuguo commented May 18, 2017

@blackbbc 我试了下 不需要修改全部中文,databinding表达式中的中文改成@string就行了,
也不会太影响效果。项目就四五处需要修改。
例如:
android:text='@{"播放:"+viewModel.result.play}' 改成
android:text='@{@string/play+viewModel.result.play}'

@quert999
Copy link
Author

懂了,谢谢dalao

@WinDerek
Copy link

Windows下添加一个环境变量JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8即可
@quert999

@quert999
Copy link
Author

@DerekDick dalao给力

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants