Skip to content

Commit

Permalink
[Android][Kotlin] fixed build after decomission of jcenter and gradle…
Browse files Browse the repository at this point in the history
… update (google#7840)

* [Android] fixed build after decomission of jcenter

JCenter[1] has been removed and now is failing android build. This
change updates the configuration to remove this and few other warnings.

1 - https://developer.android.com/studio/build/jcenter-migration

* [Kotlin] fix build for latest gradle version 8.0.1

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
  • Loading branch information
2 people authored and Jochen Parmentier committed Oct 29, 2024
1 parent e013450 commit 1c4cbd4
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 140 deletions.
36 changes: 19 additions & 17 deletions android/.project
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2014 Google, Inc.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
-->
<projectDescription>
<name>FlatBufferTest</name>
<name>FlatBufferTest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
<filteredResources>
<filter>
<id>1677235311958</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
10 changes: 4 additions & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdk 33

defaultConfig {
applicationId "com.flatbuffers.app"
minSdkVersion 26
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -113,13 +111,13 @@ android {
dependsOn(generateFbsCpp)
}
}
namespace 'com.flatbuffers.app'
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.6.1'

// If you using java runtime you can add its dependency as the example below
// implementation 'com.google.flatbuffers:flatbuffers-java:$latest_version'
Expand Down
6 changes: 3 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flatbuffers.app">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand All @@ -9,7 +8,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
60 changes: 30 additions & 30 deletions android/app/src/main/cpp/generated/animal_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

// Ensure the included flatbuffers.h is the same version as when this file was
// generated, otherwise it may not be compatible.
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
FLATBUFFERS_VERSION_MINOR == 0 &&
FLATBUFFERS_VERSION_REVISION == 8,
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
FLATBUFFERS_VERSION_MINOR == 1 &&
FLATBUFFERS_VERSION_REVISION == 21,
"Non-compatible flatbuffers version included");

namespace com {
Expand All @@ -20,23 +20,23 @@ namespace app {
struct Animal;
struct AnimalBuilder;

struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
struct Animal FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
typedef AnimalBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_NAME = 4,
VT_SOUND = 6,
VT_WEIGHT = 8
};
const flatbuffers::String *name() const {
return GetPointer<const flatbuffers::String *>(VT_NAME);
const ::flatbuffers::String *name() const {
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
}
const flatbuffers::String *sound() const {
return GetPointer<const flatbuffers::String *>(VT_SOUND);
const ::flatbuffers::String *sound() const {
return GetPointer<const ::flatbuffers::String *>(VT_SOUND);
}
uint16_t weight() const {
return GetField<uint16_t>(VT_WEIGHT, 0);
}
bool Verify(flatbuffers::Verifier &verifier) const {
bool Verify(::flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyOffset(verifier, VT_NAME) &&
verifier.VerifyString(name()) &&
Expand All @@ -49,32 +49,32 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {

struct AnimalBuilder {
typedef Animal Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
::flatbuffers::FlatBufferBuilder &fbb_;
::flatbuffers::uoffset_t start_;
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
fbb_.AddOffset(Animal::VT_NAME, name);
}
void add_sound(flatbuffers::Offset<flatbuffers::String> sound) {
void add_sound(::flatbuffers::Offset<::flatbuffers::String> sound) {
fbb_.AddOffset(Animal::VT_SOUND, sound);
}
void add_weight(uint16_t weight) {
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
}
explicit AnimalBuilder(flatbuffers::FlatBufferBuilder &_fbb)
explicit AnimalBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
flatbuffers::Offset<Animal> Finish() {
::flatbuffers::Offset<Animal> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Animal>(end);
auto o = ::flatbuffers::Offset<Animal>(end);
return o;
}
};

inline flatbuffers::Offset<Animal> CreateAnimal(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> name = 0,
flatbuffers::Offset<flatbuffers::String> sound = 0,
inline ::flatbuffers::Offset<Animal> CreateAnimal(
::flatbuffers::FlatBufferBuilder &_fbb,
::flatbuffers::Offset<::flatbuffers::String> name = 0,
::flatbuffers::Offset<::flatbuffers::String> sound = 0,
uint16_t weight = 0) {
AnimalBuilder builder_(_fbb);
builder_.add_sound(sound);
Expand All @@ -83,8 +83,8 @@ inline flatbuffers::Offset<Animal> CreateAnimal(
return builder_.Finish();
}

inline flatbuffers::Offset<Animal> CreateAnimalDirect(
flatbuffers::FlatBufferBuilder &_fbb,
inline ::flatbuffers::Offset<Animal> CreateAnimalDirect(
::flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
const char *sound = nullptr,
uint16_t weight = 0) {
Expand All @@ -98,32 +98,32 @@ inline flatbuffers::Offset<Animal> CreateAnimalDirect(
}

inline const com::fbs::app::Animal *GetAnimal(const void *buf) {
return flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
return ::flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
}

inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
return ::flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
}

inline bool VerifyAnimalBuffer(
flatbuffers::Verifier &verifier) {
::flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
}

inline bool VerifySizePrefixedAnimalBuffer(
flatbuffers::Verifier &verifier) {
::flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
}

inline void FinishAnimalBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<com::fbs::app::Animal> root) {
::flatbuffers::FlatBufferBuilder &fbb,
::flatbuffers::Offset<com::fbs::app::Animal> root) {
fbb.Finish(root);
}

inline void FinishSizePrefixedAnimalBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<com::fbs::app::Animal> root) {
::flatbuffers::FlatBufferBuilder &fbb,
::flatbuffers::Offset<com::fbs::app::Animal> root) {
fbb.FinishSizePrefixed(root);
}

Expand Down
13 changes: 11 additions & 2 deletions android/app/src/main/java/generated/com/fbs/app/Animal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import java.nio.ByteOrder
import kotlin.math.sign

@Suppress("unused")
@kotlin.ExperimentalUnsignedTypes
class Animal : Table() {

fun __init(_i: Int, _bb: ByteBuffer) {
Expand All @@ -31,14 +32,22 @@ class Animal : Table() {
val name : String?
get() {
val o = __offset(4)
return if (o != 0) __string(o + bb_pos) else null
return if (o != 0) {
__string(o + bb_pos)
} else {
null
}
}
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
val sound : String?
get() {
val o = __offset(6)
return if (o != 0) __string(o + bb_pos) else null
return if (o != 0) {
__string(o + bb_pos)
} else {
null
}
}
val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1)
fun soundInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.10"
ext.kotlin_version = "1.7.21"
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -17,7 +17,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 5 additions & 14 deletions kotlin/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ import org.jetbrains.kotlin.ir.backend.js.compile

plugins {
kotlin("multiplatform")
id("org.jetbrains.kotlin.plugin.allopen") version "1.4.20"
id("org.jetbrains.kotlinx.benchmark") version "0.4.2"
id("io.morethan.jmhreport") version "0.9.0"
id("org.jetbrains.kotlinx.benchmark")
id("io.morethan.jmhreport")
id("de.undercouch.download")
}

// allOpen plugin is needed for the benchmark annotations.
// for more information, see https://github.com/Kotlin/kotlinx-benchmark#gradle-plugin
allOpen {
annotation("org.openjdk.jmh.annotations.State")
}

group = "com.google.flatbuffers.jmh"
version = "2.0.0-SNAPSHOT"

Expand All @@ -34,7 +27,7 @@ benchmark {
iterationTime = 300
iterationTimeUnit = "ms"
// uncomment for benchmarking JSON op only
// include(".*JsonBenchmark.*")
include(".*JsonBenchmark.*")
}
}
targets {
Expand All @@ -43,9 +36,7 @@ benchmark {
}

kotlin {
jvm {
withJava()
}
jvm()

sourceSets {

Expand All @@ -58,7 +49,7 @@ kotlin {
implementation(kotlin("stdlib-common"))
implementation(project(":flatbuffers-kotlin"))
implementation(libs.kotlinx.benchmark.runtime)

implementation("com.google.flatbuffers:flatbuffers-java:2.0.3")
// json serializers
implementation(libs.moshi.kotlin)
implementation(libs.gson)
Expand Down
Loading

0 comments on commit 1c4cbd4

Please sign in to comment.