我无法为我的Google Pixel C平板电脑找到适合ADB的驱动程序.我正在开发Windows 8.1.我有来自Google的最新USB驱动程序,但当我为此设备选择它们时,它们不会被识别为兼容.我猜我是否从我的驱动程序列表中手动选择了ADB接口,它会起作用,但Windows会在这样做时发出警告.Google是否在Pixel C的基础上发布了他们的驱动程序?
Gradle似乎在我正在进行的项目中丢失了构建类型.我可以重新创建一个小问题,如下所示.我有以下文件:
build.gradle
local.properties
src/main/AndroidManifest.xml
Run Code Online (Sandbox Code Playgroud)
的build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 1
targetSdkVersion 23
}
buildTypes {
debug {
}
release {
}
}
}
Run Code Online (Sandbox Code Playgroud)
local.properties:
sdk.dir=/path/to/android-sdk-linux
Run Code Online (Sandbox Code Playgroud)
的src/main/AndroidManifest.xml中:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example"/>
Run Code Online (Sandbox Code Playgroud)
我希望摇篮生成任务installDebug和installRelease,因为我定义debug和release作为buildTypes.但事实并非如此.该命令gradle tasks产生:
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
...
Install tasks
-------------
installDebug …Run Code Online (Sandbox Code Playgroud) 我有一个正在开发的 Pixel-C。我的最低 API 级别是 21,这也是 ART 取代 Dalvik 的级别。我已经尝试过以下两种方法:
adb shell setprop dalvik.vm.enableassertions all
adb shell setprop debug.assert 1
Run Code Online (Sandbox Code Playgroud)
他们似乎执行成功。我已经放置
assert false : "assertions are active!";
Run Code Online (Sandbox Code Playgroud)
在我的 onStart 中,我在 logcat 中没有看到任何堆栈跟踪。我希望应用程序在我安装并运行后立即退出。请告诉我如何让这个断言执行。
请不要提及 JUnit 或其他进行断言的方法,也不要提及任何需要显式抛出错误的解决方案。生产代码永远不应该抛出错误,也不应该尝试捕捉和处理它们。这就是为什么将断言添加到语言中的原因,以便在测试环境中违反不变量时导致应用程序崩溃,而不会在生产中产生任何开销或风险。
这个 6 年前的问题基本相同,但对于 Dalvik(IE 过时),解决方案要么不起作用,要么不好: 我可以在 Android 设备上使用断言吗?
我可以从 ORM(Cupboard)中获取 POJO,但我不知道如何编写 xml 来绑定到这样的列表。除了非常简短地提到在 ListView 或 RecyclerView 中使用它们之外,所有示例都是单一的。因此,我尝试在 xml 文件中使用单一绑定,并为每个项目再次“膨胀”。该代码如下:
private void listThings() {
LinearLayout gList = (LinearLayout) findViewById(R.id.thingList);
gList.removeAllViews();
SQLiteDatabase db = new CGDatabaseHandler(gList.getContext()).getReadableDatabase();
DatabaseCompartment dbc = cupboard().withDatabase(db);
QueryResultIterable<Thing> itr = null;
try {
itr = dbc.query(Thing.class).query();
for (Thing thing : itr) {
// use data binding to create a UI widget for each
LayoutInflater inflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ThingDocumentLabelBinding binding = DataBindingUtil.inflate(inflater,
R.layout.thing_document_label, gList, false);
binding.setThing(thing);
//
gList.addView(binding.getRoot());
}
} finally {
// close …Run Code Online (Sandbox Code Playgroud) 我需要修改 gradle 为distTar任务生成的启动脚本。我似乎能够设置 unixStartScriptGenerator.template如下所示,但是当我从 tar 解压缩脚本时,我的更改不存在。
这是我的完整内容build.gradle:
apply plugin: 'java'
apply plugin: 'war'
// to use the main method in Main, which uses Jetty
apply plugin: 'application'
mainClassName = 'com.example.Main'
project.version = '2017.0.0.0'
repositories {
mavenLocal()
mavenCentral()
}
task createStartScripts(type: CreateStartScripts) {
// based on https://github.com/gradle/gradle/tree/v3.5.0/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins
def tplName = 'unixStartScriptTemplate.txt'
// this succeeds. I tried negating it to ensure that it runs, and it failed, so it's running.
assert project.file(tplName).exists();
unixStartScriptGenerator.template = project.file(tplName).newReader() as …Run Code Online (Sandbox Code Playgroud) java software-distribution gradle build.gradle gradle-plugin
我正在启动一个API级别最低为21的项目,试图找出实现ActionBar的正确方法.官方文档从使用appcompat库开始,列出的主要优点是它保持兼容性回到7级.我甚至不想要预先安装Lollipop.我应该使用appcompat吗?放弃appcompat库有什么优点或缺点吗?
android android-appcompat android-actionbar android-5.0-lollipop android-api-levels
关于泛型,我被告知铸造是坏的,并且通常有一些方法可以完全消除铸造,因为编译器在检查程序时能够做到最好.在这里将ChangeListener添加到ReadOnlyDoubleProperty似乎打败了这个理想.这是API中的缺陷,还是规则的例外,还是实际上有一些方法可以使这段代码看起来很好?
nodeA.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue< ? extends Number > observable,
Number oldValue,
Number newValue ) {
final double ov = oldValue.doubleValue();
final double nv = newValue.doubleValue();
@SuppressWarnings("unchecked")
final ObservableValue<Double> ob = ( ObservableValue< Double > ) observable;
// do stuff
}
});
Run Code Online (Sandbox Code Playgroud)
首先,我可以在ChangeListener上使用的最具体的类型参数是Number.我应该可以使用Double!这是DoubleExpression!由于这个问题,我必须解压缩changed方法的参数.请帮助减少这里的行数.Lambdas可以减少行数,但我会特别询问泛型.
对于整数,这项任务很简单.
private int x;
private int y
private int checksOut;
public TestCase(int input, int checksOut) {
if (input == Integer.MAX_VALUE) {
throw new IllegalArgumentException("can't increment MAX_VALUE");
}
this.x = input;
this.y = input +1;
this.checksOut = checksOut;
}
@Test
public void test() {
boolean biggerThanY = y <= checksOut;
boolean smallerThanX = x >= checksOut;
assertTrue(biggerThanY || smallerThanX);
}
Run Code Online (Sandbox Code Playgroud)
如何使用原始浮点数而不是整数重写此测试,以便找不到任何未通过测试的输入和checksOut值?