Categories
discuss

java.lang.NoSuchMethodError on compile

I’m trying to compile an Android project unsuccessfully. The error message is:

Execution failed for task ‘:mobile:_compileAppDebug’.

java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;

Here are my module’s gradle dependencies in which I specify a number of libraries including google Auto:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':library')
    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
    provided 'com.google.auto.value:auto-value:1.0-rc1'
    apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
    provided 'org.glassfish:javax.annotation:10.0-b28' 
    compile 'com.jakewharton:butterknife:6.1.0' 
    compile 'com.f2prateek.dart:dart:1.1.0'
}

When I looked at the dependencies I thought I just needed google auto value since that is where the missing method resides but adding the provided does not resolve the issue.

The project gradle file includes the retrolambda plugin

dependencies {
    classpath 'me.tatarka:gradle-retrolambda:2.5.0'
    classpath 'com.android.tools.build:gradle:1.0.1'
    classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
    classpath 'io.fabric.tools:gradle:1.+'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}

Can anyone help me identify which dependencies cause the compile error? Interestingly enough, when I copy the gradle files into an empty project everything runs fine.

Answer

Dagger 2.0-SNAPSHOT depends on an Auto SNAPSHOT which had an API change: https://github.com/google/dagger/issues/113

This is perfectly normal and acceptable thing for libraries which are under development. If you cannot tolerate an occasional broken build, do not depend on non-release versions in a manner that can change at any time without warning.

Categories
discuss

Member variables in ES6 classes

Is there any way to use the ECMAScript6 class notation to declare either a static class variable or a default value for an instance variable? Without class what I have in mind would be written as

function MyClass(arg) { if(arg) this.arg = arg; }
MyClass.classVariable = 42;
MyClass.prototype.arg = "no arg specified";

The most obvious ES6-like notation in my opinion would have been

class MyClass {
    constructor(arg) { if(arg) this.arg = arg; }
    static let classVariable = 42;
    let arg = "no arg specified";
}

But this doesn’t work, since according to the current spec draft the only productions of ClassElement are static and instance methods and semicolons all by themselves. OK, one can use a pair of getter and setter methods to achieve similar semantics to what I outlined, but I guess at a severe performance penalty and with really bizarre syntax.

Is there some draft which suggests including variables in the class notation, one way or another? If so, what was the suggested syntax, where was it published, where was it discussed, how did the discussion go, and what’s the current state of affairs on that front? As it stands, this question can’t be answered if no such thing has been discussed before, at any level, but I consider that unlikely.


A bit of background: I’m currently toying with the Google closure compiler performing advanced compilation, using ES6 as input. For that to work, I need a place to put my type annotations for member variables, and I used to place them using syntax like /** @type {string} */ MyClass.prototype.arg; which is a semantic no-op in ECMAScript but provides the type information to the closure compiler nice and easy. I haven’t yet found a similarly nice way to do this with a class construct. But if you care to address this aspect, that would be a comment. The question above is about member declarations which are more than no-ops, so that’s what an answer here should discuss.

Answer

ES6 will almost certainly not cover syntax for defining class variables. Only methods and getters/setters can be defined using the class syntax. This means you’ll still have to go the MyClass.classVariable = 42; route for class variables.

If you just want to initialize a class with some defaults, there is a rich new syntax set for function argument and destructuring defaults you can use. To give a simple example:

class Foo {
    constructor(foo = 123) {
        this.foo = foo;
    }
}

new Foo().foo == 123
new Foo(42).foo == 42
Categories
discuss

How to force Bluetooth LE “Just Works” Pairing in Android

I have an embedded system running a GATT server that I am trying to connect to via Android. The task is simple: connect to the GATT server, navigate characteristics, and validate read/write capabilities. The problem is when I try and connect with an Android app, it attempts to pair with a “Passkey” instead of with “Just Works” [https://developer.bluetooth.org/TechnologyOverview/Pages/LE-Security.aspx]. This isn’t acceptable as my embedded device does not have any method of displaying a key to the user to use for pairing. So the connection method must be Just Works.

I have tried numerous apps from the Play store and all of them only attempt to pair with Passkey. But this is the current one I am working with: https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner

I have this working using the LightBlue application (supported in OS X and iOS). So I know my peripheral (GATT server) is working: advertising, connectable, characteristic accessible, etc.

How do I force Android to use Just Works instead of Passkey pairing? Is there a peripheral configuration I’m missing?

Thanks

Answer

The root of the issue was the mode the Linux interface was in. Bluetooth devices that support both BR/EDR (Classic) and LE by default are in dual-mode. That is, they can operate as a Classic or LE device. I do not have insight into the Android API and have not attempted to develop an Android app that can detect a dual-mode device and choose to connect as LE using Just Working pairing. But I was able to disable BR/EDR on the interface and validate Android detected it during scan as an LE only (single-mode) interface. The Android app then connected seamlessly using Just Working pairing.

Here is how I disabled BR/EDR on the interface:

$ sudo hciconfig hci0 down
$ sudo ./btmgmt bredr off
hci0 Set BR/EDR complete, settings: connectable bondable le 
$ sudo hciconfig hci0 up
$ sudo hciconfig hci0 leadv

You can build the btmgmt application in Linux by downloading and building Bluez. The btmgmt application is built conditionally on the --enable-experimental config parameter.

UPDATE: Another approach is instead of modifying the interface capabilities, just modify the broadcasted interface capabilities. This is done through the advertisement flags. Modify the flags to broadcast that BR/EDR is not supported. This is bit 2 and would creates a flags broadcast of 0x04. (See Bluetooth SIG doc CSS v4: Part A, Section 1.3.2)

Categories
discuss

Can’t change Radio Button color on Android

I’m using Android Studio. I need to change the color of the Radio Button, after changing the Button Tint Color value to the one I need it works on the preview, but whenever I launch the app on a device the button is the standard green/blue-ish color.

Is this some kind of device API level issue? If so, is it possible to change the color for older devices?

Answer

After reading @Ranjith’s answer i did a little digging and this seemed to work. Just add it to your AppTheme.

    //red is the color of the pressed state and activated state
    <item name="colorControlActivated">@android:color/holo_red_light</item>
    //black is the color of the normal state
    <item name="colorControlNormal">@android:color/black</item>

My question is how do you do this programatically as I have dynamic radio buttons??

Categories
discuss

Spring Could not Resolve placeholder

I’m fairly new to spring so excuse me if this is a dumb question. When I try to launch a program I get the following error: java.lang.IllegalArgumentException: Could not resolve placeholder 'appclient' in string value [${appclient}]. The error is thrown when the following code is executed:

package ca.virology.lib2.common.config.spring.properties;
import ca.virology.lib2.config.spring.PropertiesConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

@Configuration
@Import({PropertiesConfig.class})
@PropertySource("${appclient}")
public class AppClientProperties {
private static final Logger log = LoggerFactory.getLogger(AppClientProperties.class);
{
    //this initializer block will execute when an instance of this class is created by Spring
    log.info("Loading AppClientProperties");
}
@Value("${appclient.port:}")
private int appClientPort;

@Value("${appclient.host:}")
private String appClientHost;

public int getAppClientPort() {
    return appClientPort;
}

public String getAppClientHost() {
    return appClientHost;
}
}

A property file called appclient.properties exists in the resources folder with the information for host and port. I’m not sure where the "${appclient}" is defined, if it is at all. Maybe it is not even defined and that is causing the problem. Do I need to change the "${appclient}" to something like "{classpath:/appclient.properties}" or am I missing something else?

Answer

You are not reading the properties file correctly. The propertySource should pass the parameter as: file:appclient.properties or classpath:appclient.properties. Change the annotation to:

@PropertySource(value={"classpath:appclient.properties"})

However I don’t know what your PropertiesConfig file contains, as you’re importing that also. Ideally the @PropertySource annotation should have been kept there.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..