1

我正在尝试为狂暴的信标做一个简单的应用程序,但是当我启动该应用程序时它会停止。我想我用“添加外部 jar”正确导入了 sdk。

进口的sdk

我更改了 android manifest 来做蓝牙权限和其他事情......

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
...
<service android:name="com.estimote.sdk.service.BeaconService" android:exported="false"/>

这是错误日志:

02-25 13:25:45.431: E/dalvikvm(9326): Could not find class 'com.estimote.sdk.Region', referenced from method com.example.beacons.MainActivity.<clinit>
02-25 13:25:45.431: W/dalvikvm(9326): VFY: unable to resolve new-instance 710 (Lcom/estimote/sdk/Region;) in Lcom/example/beacons/MainActivity;
02-25 13:25:45.431: D/dalvikvm(9326): VFY: replacing opcode 0x22 at 0x0001
02-25 13:25:45.431: D/dalvikvm(9326): DexOpt: unable to opt direct call 0x13b3 at 0x07 in Lcom/example/beacons/MainActivity;.<clinit>
02-25 13:25:45.431: W/dalvikvm(9326): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/example/beacons/MainActivity;
02-25 13:25:45.431: W/dalvikvm(9326): Class init failed in newInstance call (Lcom/example/beacons/MainActivity;)
02-25 13:25:45.431: D/AndroidRuntime(9326): Shutting down VM
02-25 13:25:45.431: W/dalvikvm(9326): threadid=1: thread exiting with uncaught exception (group=0x41599ba8)
02-25 13:25:45.431: E/AndroidRuntime(9326): FATAL EXCEPTION: main
02-25 13:25:45.431: E/AndroidRuntime(9326): Process: com.example.beacons, PID: 9326
02-25 13:25:45.431: E/AndroidRuntime(9326): java.lang.NoClassDefFoundError: com.estimote.sdk.Region
02-25 13:25:45.431: E/AndroidRuntime(9326):     at com.example.beacons.MainActivity.<clinit>(MainActivity.java:18)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at java.lang.Class.newInstanceImpl(Native Method)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at java.lang.Class.newInstance(Class.java:1208)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.os.Looper.loop(Looper.java:136)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at java.lang.reflect.Method.invoke(Method.java:515)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-25 13:25:45.431: E/AndroidRuntime(9326):     at dalvik.system.NativeStart.main(Native Method)
02-25 13:30:45.704: I/Process(9326): Sending signal. PID: 9326 SIG: 9

我不知道为什么它说找不到类'com.estimote.sdk.Region'......

这是主要活动

package com.example.beacons;

import java.util.List;

import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;

import android.os.Bundle;
import android.os.RemoteException;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {
    private static final String ESTIMOTE_PROXIMITY_UUID = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
    private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", ESTIMOTE_PROXIMITY_UUID, null, null);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void bluetoothTest(View view){
        Toast.makeText(getBaseContext(),"Listener works", Toast.LENGTH_SHORT).show();
    }

}

如果我删除这一行:

private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", ESTIMOTE_PROXIMITY_UUID, null, null);

一切正常,触摸屏幕上的 1 个按钮时我可以看到吐司。

4

2 回答 2

1

Eclipse 出于某种原因没有将 jar 打包到 apk 中。

请参阅:https ://stackoverflow.com/a/11003202或https://stackoverflow.com/a/14125846在 Android 项目中引用(纯 java)项目(找不到类)

于 2014-02-25T21:30:36.067 回答
1

我遇到了同样的麻烦。就我而言,是使用 Unity3D 和 estimote 服务。关键是给currentActivity添加一个没有UI的fragment。

示例:这在启动信标的文件中。在您的情况下,如果您从活动中执行此操作,则可以擦除 UnityPlayer.currentActivity,因为此示例用于与统一项目混合

    fragment = new BeaconsFragment();
    android.app.FragmentManager fragmentManager = UnityPlayer.currentActivity.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(fragment, "thread_beacons");
    fragmentTransaction.commit()
于 2014-12-26T04:05:17.940 回答