我正在使用Google Blockly for Android。我使用Blockly开发人员工具创建了自定义块,并将其添加到我的assets文件夹中,并在我的应用程序代码中引用了它,以下是我的Main方法代码:
import android.os.Handler;
import android.support.annotation.NonNull;
import android.util.Log;
import android.webkit.WebView;
import android.widget.Toast;
import com.evgenii.jsevaluator.JsEvaluator;
import com.evgenii.jsevaluator.interfaces.JsCallback;
import com.google.blockly.android.AbstractBlocklyActivity;
import com.google.blockly.android.codegen.CodeGenerationRequest;
import com.google.blockly.android.codegen.LoggingCodeGeneratorCallback;
import com.google.blockly.model.DefaultBlocks;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends AbstractBlocklyActivity {
JsEvaluator jsEvaluator = new JsEvaluator(this);
private static final String TAG = "SimpleActivity";
private static final String SAVE_FILENAME = "simple_workspace.xml";
private static final String AUTOSAVE_FILENAME = "simple_workspace_temp.xml";
public static final String TOOLBOX_PATH = "roboapp_toolbox1.xml";
// Add custom blocks to this list.
private static final List<String> BLOCK_DEFINITIONS = Arrays.asList(
"blocks/block_definitions.json"
);
private static final List<String> JAVASCRIPT_GENERATORS = Arrays.asList(
// Custom block generators go here. Default blocks are already
included.
"blocks/code_generator.js"
);
private final Handler mHandler = new Handler();
private final CodeGenerationRequest.CodeGeneratorCallback
mCodeGeneratorCallback =
new CodeGenerationRequest.CodeGeneratorCallback() {
@Override
public void onFinishCodeGeneration(final String generatedCode) {
// Toast.makeText(getApplicationContext(),
generatedCode,Toast.LENGTH_SHORT).show();
mHandler.post(new Runnable() {
@Override
public void run() {
jsEvaluator.evaluate(generatedCode, new JsCallback()
{
@Override
public void onResult(String result) {
// Process result here.
// This method is called in the UI thread.
Toast.makeText(getApplicationContext(),
result.toString(),Toast.LENGTH_LONG).show();
}
@Override
public void onError(String errorMessage) {
// Process JavaScript error here.
// This method is called in the UI thread.
}
});
}
});
}
};
/*CodeGenerationRequest.CodeGeneratorCallback mCodeGeneratorCallback =
new LoggingCodeGeneratorCallback(this, TAG);*/
@NonNull
@Override
protected List<String> getBlockDefinitionsJsonPaths() {
return BLOCK_DEFINITIONS;
}
@NonNull
@Override
protected String getToolboxContentsXmlPath() {
// Replace with a toolbox that includes application specific blocks.
return TOOLBOX_PATH;
}
@NonNull
@Override
protected List<String> getGeneratorsJsPaths() {
return JAVASCRIPT_GENERATORS;
}
@NonNull
@Override
protected CodeGenerationRequest.CodeGeneratorCallback getCodeGenerationCallback() {
// Uses the same callback for every generation call.
return mCodeGeneratorCallback;
}
/**
* Optional override of the save path, since this demo Activity has multiple Blockly
* configurations.
* @return Workspace save path used by SimpleActivity and SimpleFragment.
*/
@Override
@NonNull
protected String getWorkspaceSavePath() {
return SAVE_FILENAME;
}
/**
* Optional override of the auto-save path, since this demo Activity has multiple Blockly
* configurations.
* @return Workspace auto-save path used by SimpleActivity and SimpleFragment.
*/
@Override
@NonNull
protected String getWorkspaceAutosavePath() {
return AUTOSAVE_FILENAME;
}
}
所有块定义,代码生成器和工具箱文件都在代码中提到的各自位置。
**现在我的问题是,在运行应用程序时,安装了apk但应用程序停止运行。 **。它在运行中显示以下错误:
java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String
android.os.SystemProperties.native_get(java.lang.String) (tried
Java_android_os_SystemProperties_native_1get and
Java_android_os_SystemProperties_native_1get__Ljava_lang_String_2)
at android.os.SystemProperties.native_get(Native Method)
at android.os.SystemProperties.get(SystemProperties.java:52)
at android.os.Environment.getCanonicalPathOrNull(Environment.java:832)
at android.os.Environment.<clinit>(Environment.java:83)
at android.os.Environment.
getLegacyExternalStorageDirectory(Environment.java:419)
at android.os.Debug.<clinit>(Debug.java:101)
at android.ddm.DdmHandleHello.handleHELO(DdmHandleHello.java:164)
at android.ddm.DdmHandleHello.handleChunk(DdmHandleHello.java:91)
at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
java.lang.UnsatisfiedLinkError: android.os.Debug
at android.ddm.DdmHandleHello.handleFEAT(DdmHandleHello.java:176)
at android.ddm.DdmHandleHello.handleChunk(DdmHandleHello.java:93)
at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
java.lang.UnsatisfiedLinkError: android.os.Debug
at android.ddm.DdmHandleProfiling.handleMPRQ(DdmHandleProfiling.java:187)
at android.ddm.DdmHandleProfiling.handleChunk(DdmHandleProfiling.java:88)
at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
Aborted
并且Logcat显示以下错误:
FATAL EXCEPTION: main
Process: app.robo.com.roboapp, PID: 13104
java.lang.RuntimeException: Unable to start activity ComponentInfo{app.robo.com.roboapp/app.robo.com.roboapp.MainActivity}:
java.lang.IllegalStateException: Failed to load toolbox XML.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.IllegalStateException: Failed to load toolbox XML.
at com.google.blockly.android.BlocklyActivityHelper.reloadToolbox(BlocklyActivityHelper.java:670)
at com.google.blockly.android.AbstractBlocklyActivity.reloadToolbox(AbstractBlocklyActivity.java:649)
at com.google.blockly.android.AbstractBlocklyActivity.onCreate(AbstractBlocklyActivity.java:256)
at android.app.Activity.performCreate(Activity.java:6092)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.io.FileNotFoundException: blocks/roboapp_toolbox1.xml
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:318)
at android.content.res.AssetManager.open(AssetManager.java:292)
at com.google.blockly.android.BlocklyActivityHelper.reloadToolbox(BlocklyActivityHelper.java:667)
at com.google.blockly.android.AbstractBlocklyActivity.reloadToolbox(AbstractBlocklyActivity.java:649)
at com.google.blockly.android.AbstractBlocklyActivity.onCreate(AbstractBlocklyActivity.java:256)
at android.app.Activity.performCreate(Activity.java:6092)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
我的工具箱xml由Blockly Developer工具生成,如下所示:
<toolbox>
<category name="Movements" colour="#5ba5a5">
<block type="movement_robot">
<field name="time">1</field>
<field name="angle">90</field>
<field name="NAME">slow</field>
</block>
<block type="movement_stop"></block>
<block type="movement_speed">
<field name="setspeed">sspeed</field>
<field name="NAME">90</field>
</block>
</category>
<category name="Controls" colour="#a56d5b">
<block type="control_for_do">
<field name="time">0</field>
</block>
<block type="control_wait">
<field name="time">0</field>
</block>
<block type="control_exit"></block>
</category>
<category name="Loops" colour="#6da55b">
<block type="controls_repeat_ext">
<value name="TIMES">
<shadow type="math_number">
<field name="NUM">10</field>
</shadow>
</value>
</block>
<block type="controls_whileUntil">
<field name="MODE">WHILE</field>
</block>
</category>
<category name="Appearance" colour="#5b6da5">
<block type="app_headlights">
<value name="NAME">
<block type="logic_boolean">
<field name="BOOL">FALSE</field>
</block>
</value>
</block>
<block type="app_backlight">
<value name="NAME">
<block type="logic_boolean">
<field name="BOOL">FALSE</field>
</block>
</value>
</block>
</category>
</toolbox>
答案 0 :(得分:0)
FileNotFoundException: blocks/roboapp_toolbox1.xml
确保您的工具箱XML位于assets/blocks/roboapp_toolbox1.xml
?