0

我正在使用 Lex 制作一个带有语音操作的应用程序。我通过将 aar 文件添加到项目的 libs forler 并将这些行添加到 gradle 文件中来手动导入 lex 库。

compile(name:'aws-android-sdk-core-2.4.0',ext:'jar')
compile(name:'aws-android-sdk-lex-2.4.0',ext:'aar')

我通过添加从库中创建了麦克风组件

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:context="com.sample.app.MainActivity">

<com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView xmlns:android="http://schemas.android.com/apk/res/android"
    class = "com.sample.app"
    android:layout_width="108dp"
    android:layout_height="108dp"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"
    android:background="@color/transparent"
    android:id="@+id/voiceInterface" />

</RelativeLayout>

当我尝试运行该应用程序时,它给了我以下错误

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.sample.app, PID: 14844
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sample.app.MainActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                  at android.app.ActivityThread.-wrap11(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:148)
                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
               Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
                  at android.app.Activity.setContentView(Activity.java:2172)
                  at com.sample.app.MainActivity.onCreate(MainActivity.java:418)
                  at android.app.Activity.performCreate(Activity.java:6251)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
               Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView
                  at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                  at android.app.Activity.setContentView(Activity.java:2172) 
                  at com.sample.app.MainActivity.onCreate(MainActivity.java:418) 
                  at android.app.Activity.performCreate(Activity.java:6251) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
               Caused by: java.lang.reflect.InvocationTargetException
                  at java.lang.reflect.Constructor.newInstance(Native Method)
                  at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                  at android.app.Activity.setContentView(Activity.java:2172) 
                  at com.sample.app.MainActivity.onCreate(MainActivity.java:418) 
                  at android.app.Activity.performCreate(Activity.java:6251) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
               Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/amazonaws/services/lex/R$drawable;
                  at com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView.init(InteractiveVoiceView.java:167)
                  at com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView.<init>(InteractiveVoiceView.java:147)
                  at java.lang.reflect.Constructor.newInstance(Native Method) 
                  at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                  at android.app.Activity.setContentView(Activity.java:2172) 
                  at com.sample.MainActivity.onCreate(MainActivity.java:418) 
                  at android.app.Activity.performCreate(Activity.java:6251) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.amazonaws.services.lex.R$drawable" on path: DexPathList[[zip file "/data/app/com.sample.android.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sample.android.app-1/lib/arm, /data/app/com.sample.android.app-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                  at com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView.init(InteractiveVoiceView.java:167) 
                  at com.amazonaws.mobileconnectors.lex.interactionkit.ui.InteractiveVoiceView.<init>(InteractiveVoiceView.java:147) 
                  at java.lang.reflect.Constructor.newInstance(Native Method) 
                  at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                  at android.app.Activity.setContentView(Activity.java:2172) 
                  at com.sample.app.MainActivity.onCreate(MainActivity.java:418) 
                  at android.app.Activity.performCreate(Activity.java:6251) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                Suppressed: java.lang.ClassNotFoundException: com.amazonaws.services.lex.R$drawable
                  at java.lang.Class.classForName(Native Method)
                  at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                  at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                        ... 27 more
               Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack

这是主要活动文件:-

public class MainActivity extends Activity implements InteractiveVoiceView.InteractiveVoiceListener {
private Context appContext;
private InteractiveVoiceView voiceView;
private InteractiveVoiceViewAdapter voiceViewAdapter;
private WebView mWebView;
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    appContext = getApplicationContext();
    voiceView = (InteractiveVoiceView) findViewById(R.id.voiceInterface);
    mWebView = (WebView) findViewById(R.id.activity_main_webview);
    voiceView.setInteractiveVoiceListener(this);
    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
            getApplicationContext(),
            "us-east-1:-------------------------", // Identity Pool ID
            Regions.-------- // Region
    );
    voiceView.getViewAdapter().setCredentialProvider(credentialsProvider);
    voiceView.getViewAdapter().setInteractionConfig(
            new InteractionConfig(appContext.getString(R.string.bot_name),
                    appContext.getString(R.string.bot_alias)));
    voiceView.getViewAdapter().setAwsRegion(appContext.getString(R.string.aws_region));
    voiceView.setBackgroundColor(Color.TRANSPARENT);
    voiceView.getKeepScreenOn();
 }
4

1 回答 1

0

这里有一个 Lex 示例正在运行: https ://github.com/awslabs/aws-sdk-android-samples/tree/master/LexSample

于 2017-04-28T00:06:37.777 回答