E / ARCore-AuthenticationManager:AuthenticationManager构建期间发生异常:> com.google.android.gms.common.GoogleApiAvailability java.lang.ClassNotFoundException:com.google.android.gms.common.GoogleApiAvailability 在java.lang.Class.classForName(本机方法) 在java.lang.Class.forName(Class.java:453) 在com.google.ar.persistence.AuthenticationManager.a(PG:72) 在com.google.ar.persistence.AuthenticationManager。(PG:4) 在com.google.ar.persistence.AuthenticationManagerFactory.create(PG:3) com.google.ar.core.Session.nativeCreateSessionAndWrapperWithFeatures(本机方法) 在com.google.ar.core.Session。(Session.java:14) 在com.google.ar.sceneform.ux.BaseArFragment.createSessionWithFeatures(BaseArFragment.java:419) 在com.google.ar.sceneform.ux.BaseArFragment.createSession(BaseArFragment.java:405) 在com.google.ar.sceneform.ux.BaseArFragment.initializeSession(BaseArFragment.java:379) com.google.ar.sceneform.ux.BaseArFragment.onResume(BaseArFragment.java:338) 在androidx.fragment.app.Fragment.performResume(Fragment.java:2649) 在androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:922) 在androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238) 在androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303) 在androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2659) 在androidx.fragment.app.FragmentManagerImpl.dispatchResume(FragmentManagerImpl.java:2625) 在androidx.fragment.app.FragmentController.dispatchResume(FragmentController.java:268) 在androidx.fragment.app.FragmentActivity.onResumeFragments(FragmentActivity.java:479) 在androidx.fragment.app.FragmentActivity.onPostResume(FragmentActivity.java:468) 在androidx.appcompat.app.AppCompatActivity.onPostResume(AppCompatActivity.java:195) 在android.app.Activity.performResume(Activity.java:7430) 在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3820) 在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3860) 在android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51) 在android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145) 在android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1831) 在android.os.Handler.dispatchMessage(Handler.java:106) 在android.os.Looper.loop(Looper.java:201) 在android.app.ActivityThread.main(ActivityThread.java:6823) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:547) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 由以下原因引起:java.lang.ClassNotFoundException:在路径:DexPathList [[zip file“ /data/app/com.example.ballongame-mBXuc8TN4lE0p7B5q3KzdA== /base.apk"],nativeLibraryDirectories=[/data/app/com.example.ballongame-mBXuc8TN4lE0p7B5q3KzdA==/lib/arm64,/data/app/com.example.ballongame-mBXuc8TN4lE0p7B5q3KzdA==/lib。 / arm64-v8a,/ system / lib64]] 在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:171)
package com.example.ballongame;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Point;
import android.media.AudioAttributes;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Display;
import android.widget.Button;
import android.widget.TextView;
import com.google.ar.sceneform.Camera;
import com.google.ar.sceneform.Node;
import com.google.ar.sceneform.Scene;
import com.google.ar.sceneform.collision.Ray;
import com.google.ar.sceneform.math.Vector3;
import com.google.ar.sceneform.rendering.MaterialFactory;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.rendering.ShapeFactory;
import com.google.ar.sceneform.rendering.Texture;
import java.nio.channels.InterruptedByTimeoutException;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
CustomArFragment customArFragment;
Camera camera;
Scene scene;
ModelRenderable bulletRenderable;
boolean shouldStartTimer = true;
int ballonsLeft = 20;
Point point;
TextView ballonsLeftText;
SoundPool soundPool;
int sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadSoundPool();
Display display = getWindowManager().getDefaultDisplay();
point = new Point();
display.getRealSize(point);
customArFragment = (CustomArFragment) getSupportFragmentManager().findFragmentById(R.id.arFragment);
assert customArFragment != null;
scene = customArFragment.getArSceneView().getScene();
camera = scene.getCamera();
addBallonToScene();
buildBulletModel();
Button shoot = findViewById(R.id.fire);
shoot.setOnClickListener(view -> {
if (shouldStartTimer){
startTimer();
shouldStartTimer = false;
}
});
shoot();
}
private void loadSoundPool() {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_GAME)
.build();
soundPool = new SoundPool.Builder()
.setMaxStreams(1)
.setAudioAttributes(audioAttributes)
.build();
sound = soundPool.load(this,R.raw.blop_sound,1);
}
private void shoot() {
Ray ray = camera.screenPointToRay(point.x / 2f,point.y / 2f);
Node node = new Node();
node.setRenderable(bulletRenderable);
scene.addChild(node);
new Thread(()->{
for (int i = 0;i<200;i++){
int finalI = i;
runOnUiThread(()->{
Vector3 vector3 = ray.getPoint(finalI * 0.1f);
node.setWorldPosition(vector3);
Node nodeInContact = scene.overlapTest(node);
if (nodeInContact != null){
ballonsLeft--;
ballonsLeftText.setText("Ballons Left : " + ballonsLeft);
scene.removeChild(nodeInContact);
soundPool.play(sound,1f,1f,1,0,1f);
}
});
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
runOnUiThread(()-> scene.removeChild(node));
}).start();
}
private void startTimer() {
TextView timer = findViewById(R.id.timerText);
new Thread(()-> {
int seconds = 0;
while (ballonsLeft > 0){
try {
Thread.sleep(1000);
}catch (InterruptedException e){
e.printStackTrace();
}
seconds++;
int minutePassed = seconds/60;
int secondsPassed = seconds%60;
runOnUiThread(() -> timer.setText(minutePassed + ":" + secondsPassed));
}
}).start();
}
private void buildBulletModel() {
Texture.builder()
.setSource(this,R.drawable.texture)
.build()
.thenAccept(texture -> {
MaterialFactory
.makeOpaqueWithTexture(this,texture)
.thenAccept(material -> {
bulletRenderable = ShapeFactory
.makeSphere(0.01f,
new Vector3(0f,0f,0f),
material);
});
});
}
private void addBallonToScene() {
ModelRenderable.builder()
.setSource(this, Uri.parse("balloon.sfb"))
.build()
.thenAccept(modelRenderable -> {
for (int i=0;i<20;i++)
{
Node node = new Node();
node.setRenderable(modelRenderable);
scene.addChild(node);
Random random = new Random();
int x = random.nextInt(10);
int z = random.nextInt(10);
int y = random.nextInt(20);
z=-z;
node.setWorldPosition(new Vector3(
(float)x,
y / 10f,
(float)z
));
}
});
}
}