From b56467dd1c6e4eb2f61a8068fb7d1a69ed3fa7e4 Mon Sep 17 00:00:00 2001 From: piv <> Date: Sat, 15 Oct 2022 14:30:20 +1030 Subject: [PATCH] Fix android build Fixes changes to grpc services and downgrades appcompat due to a bug in dependency versions --- .idea/.name | 1 + .idea/deploymentTargetDropDown.xml | 17 +++++++ .idea/jarRepositories.xml | 40 +++++++++++++++ README.md | 2 +- app/build.gradle | 8 +-- .../java/org/vato/carcontroller/PiLoader.java | 50 +++++++++---------- build.gradle | 3 +- 7 files changed, 90 insertions(+), 31 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/deploymentTargetDropDown.xml create mode 100644 .idea/jarRepositories.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..bb76893 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +CarController \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..c1c347f --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..818a8ed --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index cb9eab5..a94c097 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This software allows for the control of an RC Car using a linux system. Currently it's been tested to work on a Traxxas Slash and raspberry pi 3b+. -See the individuals modules for more detailed READMEs, including build instructions. +See the individual modules for more detailed READMEs, including build instructions. ### Current Functinoality diff --git a/app/build.gradle b/app/build.gradle index 8fd9e73..7a50770 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { dependencies { implementation project(':protobuf') implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.5.1' + implementation 'androidx.appcompat:appcompat:1.4.2' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.preference:preference:1.2.0' @@ -42,9 +42,9 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' - implementation 'io.grpc:grpc-okhttp:1.29.0' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-protobuf-lite:1.39.0' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-stub:1.39.0' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-okhttp:1.29.0' + implementation 'io.grpc:grpc-protobuf-lite:1.39.0' + implementation 'io.grpc:grpc-stub:1.39.0' implementation 'javax.annotation:javax.annotation-api:1.3.2' implementation 'org.zeromq:jeromq:0.5.2' } diff --git a/app/src/main/java/org/vato/carcontroller/PiLoader.java b/app/src/main/java/org/vato/carcontroller/PiLoader.java index 3531a87..d840a54 100644 --- a/app/src/main/java/org/vato/carcontroller/PiLoader.java +++ b/app/src/main/java/org/vato/carcontroller/PiLoader.java @@ -17,12 +17,12 @@ public class PiLoader implements Runnable { private Integer steeringValue = 50; private Integer throttleValue = 50; - private ManagedChannel mChannel; + private final ManagedChannel mChannel; - private CarControlGrpc.CarControlBlockingStub stub; - private AtomicBoolean stop = new AtomicBoolean(false); + private final CarControlGrpc.CarControlBlockingStub stub; + private final AtomicBoolean stop = new AtomicBoolean(false); private Thread piUpdaterThread; - private boolean useGrpcStream; + private final boolean useGrpcStream; public PiLoader(String host, Integer port, boolean useGrpcStream) { mChannel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build(); @@ -72,10 +72,10 @@ public class PiLoader implements Runnable { try { SteeringResponse steeringResponse = stub.setSteering( SteeringRequest.newBuilder().setSteering((float) steeringValue / 50f - 1) - .build()); + .build()); ThrottleResponse throttleResponse = stub.setThrottle( ThrottleRequest.newBuilder().setThrottle((float) throttleValue / 50f - 1) - .build()); + .build()); } catch (Exception e) { System.out.println("Error"); stop(); @@ -93,9 +93,9 @@ public class PiLoader implements Runnable { private void doStreamUpdates() { // Stream if user sets use_grpc_streams to true. This method is more efficient but less compatible. final CountDownLatch finishLatch = new CountDownLatch(1); - StreamObserver responseObserver = new StreamObserver() { + StreamObserver responseObserver = new StreamObserver() { @Override - public void onNext(Empty value) { + public void onNext(Vehicle2DResponse value) { finishLatch.countDown(); Log.d("PiLoader", "Finished streaming"); } @@ -113,23 +113,23 @@ public class PiLoader implements Runnable { } }; StreamObserver requestStreamObserver = CarControlGrpc.newStub(mChannel) - .streamVehicle2d( - responseObserver); + .streamVehicle2d( + responseObserver); while (!stop.get() && !Thread.interrupted() && finishLatch.getCount() > 0) { requestStreamObserver.onNext(Vehicle2DRequest.newBuilder() - .setThrottle(ThrottleRequest.newBuilder() - .setThrottle( - (float) throttleValue / - 50f - - 1) - .build()) - .setSteering(SteeringRequest.newBuilder() - .setSteering( - (float) steeringValue / - 50f - - 1) - .build()) - .build()); + .setThrottle(ThrottleRequest.newBuilder() + .setThrottle( + (float) throttleValue / + 50f - + 1) + .build()) + .setSteering(SteeringRequest.newBuilder() + .setSteering( + (float) steeringValue / + 50f - + 1) + .build()) + .build()); try { // Use the same update rate as a typical screen refresh rate. TimeUnit.MILLISECONDS.sleep(200); @@ -141,12 +141,12 @@ public class PiLoader implements Runnable { public void saveRecording() { // Ideally don't want to use a blocking stub here, android may complain. - Empty done = stub.saveRecordedData(SaveRequest.newBuilder().setFile("Test").build()); + SaveResponse done = stub.saveRecordedData(SaveRequest.newBuilder().setFile("Test").build()); } public void record(boolean record) { // Ideally don't want to use a blocking stub here, android may complain. - Empty done = stub.record(RecordingReqeust.newBuilder().setRecord(record).build()); + RecordingResponse done = stub.record(RecordingReqeust.newBuilder().setRecord(record).build()); } } diff --git a/build.gradle b/build.gradle index fe738a3..a905ce6 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ buildscript { repositories { google() + mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.3.1' @@ -16,7 +17,7 @@ buildscript { allprojects { repositories { google() - mavenLocal() + mavenCentral() } }