简体   繁体   中英

Guava ImmutableList static function checkNotNull not found

I'm pretty new with Java and Android Studio, because I mainly work under Xamarin.
I'm implementing a voice recognition project (originally developed in Xamarin but now unusable dued to great latencies introduced somewhere by Google) trying to use the new (still beta) cloud speech recognition. I've downloaded a sample from here and tried to work with it, but I'm facing a strange (for me) problem. The SpeechSettings object is using an ImmutableList to hold del default API scope, but I've a lot of errors when the ImmutableList add("something").build() try to call the checkNotNull function. I've extracted the creation of the list off from the SpeechSettings object creation and I've placed it on a Button's click event for simplicity. The creation (or better, the insertion of a String element) causes the same error list. This is the code of the click listener :

bRecon.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
        try
        {
            ImmutableList<String> lTest = ImmutableList.String>builder().add("132").build();
        }
        catch (Exception ilEx)
        {
        }

        SpeechRecon sr = new SpeechRecon();
    });
}

and this is the relative LogCat output when the ImmutableList is created :

11-24 13:26:03.007 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Preconditions.checkNotNull, referenced from method com.google.common.collect.ImmutableList.copyOf
11-24 13:26:03.007 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve static method 26168: Lcom/google/common/base/Preconditions;.checkNotNull (Ljava/lang/Object;)Ljava/lang/Object;
11-24 13:26:03.007 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x71 at 0x0000
11-24 13:26:03.017 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Joiner.appendTo, referenced from method com.google.common.collect.ImmutableCollection.toString
11-24 13:26:03.017 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve virtual method 26143: Lcom/google/common/base/Joiner;.appendTo (Ljava/lang/StringBuilder;Ljava/lang/Iterable;)Ljava/lang/StringBuilder;
11-24 13:26:03.017 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x6e at 0x0013
11-24 13:26:03.022 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Preconditions.checkNotNull, referenced from method com.google.common.collect.ImmutableList$Builder.add
11-24 13:26:03.022 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve static method 26168: Lcom/google/common/base/Preconditions;.checkNotNull (Ljava/lang/Object;)Ljava/lang/Object;
11-24 13:26:03.022 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x71 at 0x0002
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Preconditions.checkArgument, referenced from method com.google.common.collect.Lists.computeArrayListCapacity
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve static method 26164: Lcom/google/common/base/Preconditions;.checkArgument (Z)V
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x71 at 0x0003
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Preconditions.checkNotNull, referenced from method com.google.common.collect.Lists.newArrayList
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve static method 26168: Lcom/google/common/base/Preconditions;.checkNotNull (Ljava/lang/Object;)Ljava/lang/Object;
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x71 at 0x0000
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Preconditions.checkNotNull, referenced from method com.google.common.collect.Lists.newArrayList
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve static method 26168: Lcom/google/common/base/Preconditions;.checkNotNull (Ljava/lang/Object;)Ljava/lang/Object;
11-24 13:26:03.027 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x71 at 0x0000
11-24 13:26:03.032 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Preconditions.checkNotNull, referenced from method com.google.common.collect.Lists.newArrayList
11-24 13:26:03.032 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve static method 26168: Lcom/google/common/base/Preconditions;.checkNotNull (Ljava/lang/Object;)Ljava/lang/Object;
11-24 13:26:03.032 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x71 at 0x0000
11-24 13:26:03.032 31057-31057/it.sia.cloudspeechrpcjava I/dalvikvm: Could not find method com.google.common.base.Preconditions.checkNotNull, referenced from method com.google.common.collect.Lists.partition
11-24 13:26:03.032 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to resolve static method 26168: Lcom/google/common/base/Preconditions;.checkNotNull (Ljava/lang/Object;)Ljava/lang/Object;
11-24 13:26:03.032 31057-31057/it.sia.cloudspeechrpcjava D/dalvikvm: VFY: replacing opcode 0x71 at 0x0000
11-24 13:26:03.037 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to find class referenced in signature (Lcom/google/common/base/Function;)
11-24 13:26:03.037 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to find class referenced in signature (Lcom/google/common/base/Function;)
11-24 13:26:03.042 31057-31057/it.sia.cloudspeechrpcjava W/dalvikvm: VFY: unable to find class referenced in signature (Lcom/google/common/base/Function;)

and here is my gradle.build file :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "it.sia.cloudspeechrpcjava"
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        pickFirst 'META-INF/io.netty.versions.properties'
        exclude 'META-INF/INDEX.LIST'
    }
}

dependencies {
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
            {
                exclude group: 'com.android.support', module: 'support-annotations'
            })
    androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.0.1'

    compile files('libs/guava-gwt-20.0.jar')
    compile files('libs/guava-collections-r03.jar')
    compile files('libs/gax-0.0.25.jar')
    compile files('libs/grpc-all-1.0.1.jar')
    compile files('libs/grpc-core-1.0.1.jar')
    compile files('libs/grpc-core-proto-0.0.6.jar')
    compile files('libs/grpc-google-cloud-speech-v1beta1-0.1.3.jar')
    compile files('libs/joda-time-2.9.6.jar')
    compile files('libs/protobuf-java-3.1.0.jar')
}

If any of you can point me toward a possible solution it would be great. Thanks. Rodolfo.

compile files('libs/guava-collections-r03.jar') "Guava-Collections" has not been updated for 6 years and depends on a few other libraries that you haven't downloaded and included.

guava-primitives is described as "libraries that include utility classes," so it probably contains the missing Preconditions class.

Replace guava-collections with the latest version of guava (20.0) and it will probably work. I also recommend learning about automatic dependency management because manually downloading libraries and making sure the dependencies of those libraries are present will get very confusing very quickly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM