2016-11-24 2 views
0

Ich bin ziemlich neu mit Java und Android Studio, weil ich hauptsächlich unter Xamarin arbeite.
Ich implementiere ein Spracherkennungsprojekt (das ursprünglich in Xamarin entwickelt wurde, jetzt aber aufgrund der von Google eingeführten großen Latenzzeiten unbrauchbar ist) und versuche, die neue (noch immer Beta) Cloud-Spracherkennung zu verwenden. Ich habe eine Probe von here heruntergeladen und versucht, damit zu arbeiten, aber ich stehe vor einem seltsamen (für mich) Problem. Das SpeechSettings-Objekt verwendet eine ImmutableList, um den Standard-API-Bereich zu halten, aber ich habe viele Fehler, wenn die ImmutableList add("something").build() versucht, die checkNotNull-Funktion aufzurufen. Ich habe die Erstellung der Liste aus der SpeechSettings-Objekt-Erstellung extrahiert und sie zur Vereinfachung auf ein Klick-Ereignis eines Buttons platziert. Die Erstellung (oder besser das Einfügen eines String-Elements) verursacht die gleiche Fehlerliste. Dies ist der Code des Klick-Listener:Guava ImmutableList statische Funktion checkNotNull nicht gefunden

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(); 
    }); 
} 

und dies ist die relative LogCat ausgegeben, wenn der ImmutableList erstellt:

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;) 

und hier ist meine gradle.build Datei:

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') 
} 

Wenn jemand von mir auf eine mögliche Lösung hinweisen kann, wäre es großartig. Danke. Rodolfo.

Antwort

1

compile files('libs/guava-collections-r03.jar') "Guava-Sammlungen" wurde seit 6 Jahren nicht aktualisiert und hängt von einigen anderen Bibliotheken ab, die Sie nicht heruntergeladen und enthalten haben.

guava-primitives wird als "Bibliotheken, die Dienstprogramm Klassen enthalten" beschrieben, so dass es wahrscheinlich die fehlende Preconditions Klasse enthält.

Ersetzen guava-collections mit der neuesten Version guava (20.0) und es wird wahrscheinlich funktionieren. Ich empfehle auch, über automatische Abhängigkeitsverwaltung zu lernen, da das manuelle Herunterladen von Bibliotheken und das Sicherstellen, dass die Abhängigkeiten dieser Bibliotheken vorhanden sind, sehr schnell sehr verwirrend wird.

+0

Sie haben Recht. Manuelle Bibliothek Abhängigkeit für Google-Cloud-Sprache ist ein Alptraum, aber ich bin neu in Android Studio und die automatische Abhängigkeit in Form von Kompilieren 'lib_name: artefakt: version' verursachte mir Probleme mit der Aufnahme von doppelten Dateien: Mein Hauptbereich ist um meinen Kunden die Leistungsfähigkeit dieser neuen Google Speech-Plattform zu demonstrieren, ohne dabei die tiefere Lernzeit für die neue Programmierumgebung zu verlieren. Sobald ich es demonstriert habe, werde ich mehr Zeit haben, alles zu optimieren, einschließlich meines Wissens. –

Verwandte Themen