Skip to content

Commit

Permalink
chore(android): gradle 8 (#14014)
Browse files Browse the repository at this point in the history
* chore(android): let there be gradle 8
chore(android): fixed deprecations in kroll-apt project
chore(android): made kroll-apt incremental to enhance build time

* fix(android): revert change to java files
fix(android): gradle 8 compatibility update to template build.gradle
fix(android): revert dependency updates
fix(android): revert minSdk and targetSdk

* fix(android): kitchensink-app not running after gradle 8
fix(android): update _build.js & _buildModule.js for new gradle

* Update android/app/build.gradle

Co-authored-by: Chris Barber <[email protected]>

* Update android/templates/build/ti.constants.gradle

Co-authored-by: Chris Barber <[email protected]>

* Update android/titanium/build.gradle

Co-authored-by: Chris Barber <[email protected]>

* Update android/titanium/build.gradle

Co-authored-by: Chris Barber <[email protected]>

* Update android/untar.gradle

Co-authored-by: Chris Barber <[email protected]>

* Update android/titanium/build.gradle

Co-authored-by: Chris Barber <[email protected]>

* fix material.r

* github action

* optimize material imports

* optimize material imports

* fix(android): fix module building

* fix(android): bump ndk version for generated modules

---------

Co-authored-by: Hans Knöchel <[email protected]>
Co-authored-by: Chris Barber <[email protected]>
Co-authored-by: Michael Gangolf <[email protected]>
Co-authored-by: Michael Gangolf <[email protected]>
  • Loading branch information
5 people authored Sep 17, 2024
1 parent d084485 commit 50d8604
Show file tree
Hide file tree
Showing 33 changed files with 238 additions and 192 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- name: Android build
uses: ./.github/actions/build-android
with:
node-version: '16.x'
java-version: '11'
node-version: '18.x'
java-version: '17'

ios:
runs-on: macos-13
Expand All @@ -39,7 +39,7 @@ jobs:
- name: iOS build
uses: ./.github/actions/build-ios
with:
node-version: '16.x'
node-version: '18.x'

js:
runs-on: ubuntu-latest
Expand All @@ -50,10 +50,10 @@ jobs:
with:
fetch-depth: 0

- name: Use Node.js 16.x
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
cache: 'npm'

- name: Install dependencies
Expand Down Expand Up @@ -84,5 +84,5 @@ jobs:
uses: ./.github/actions/package
with:
node-version: '16.x'
java-version: '11'
java-version: '17'
vtag: ${{ env.vtag }}
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ jobs:
- name: Android build
uses: ./.github/actions/build-android
with:
node-version: '16.x'
java-version: '11'
node-version: '18.x'
java-version: '17'

ios:
runs-on: macos-13
Expand All @@ -97,7 +97,7 @@ jobs:
- name: iOS build
uses: ./.github/actions/build-ios
with:
node-version: '16.x'
node-version: '18.x'

package:
runs-on: macos-12
Expand All @@ -116,8 +116,8 @@ jobs:
- name: Package
uses: ./.github/actions/package
with:
node-version: '16.x'
java-version: '11'
node-version: '18.x'
java-version: '17'
vtag: ${{ env.vtag }}

release:
Expand Down
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ build/
/kroll-apt/bin/
/local.properties
/titanium/assets/Resources/ti.internal/build.properties
/.idea/
3 changes: 3 additions & 0 deletions android/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ apply plugin: 'com.android.application'

// Set up Android app project.
android {
compileSdkVersion 33
compileSdkVersion 34
ndkVersion project.ext.tiNdkVersion
defaultConfig {
applicationId 'com.titanium.test'
minSdkVersion 21
Expand All @@ -19,9 +20,6 @@ android {
manifestPlaceholders = project.ext.tiManifestPlaceholders
manifestPlaceholders.put('localApplicationId', applicationId) // Legacy placeholder old AARs sometimes use.
}
lintOptions {
checkReleaseBuilds false
}
sourceSets {
main {
assets.srcDirs = [
Expand All @@ -31,8 +29,12 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
namespace 'com.titanium.test'
lint {
checkReleaseBuilds false
}
}

Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
*/

buildscript {
ext.kotlin_version = '1.8.20'
ext.kotlin_version = '1.9.23'

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.android.tools.build:gradle:8.3.1'
classpath 'com.google.gms:google-services:4.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.codehaus.groovy:groovy-json:3.0.11'
classpath 'org.codehaus.groovy:groovy-json:3.0.17'
}
}

Expand Down
6 changes: 1 addition & 5 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,6 @@ AndroidBuilder.prototype.generateLibProjectForModule = async function generateLi

// Load "AndroidManifest.xml", replace ${tiapp.properties['key']} variables, and save to above directories.
const manifest = await AndroidManifest.fromFilePath(sourceManifestFilePath);
manifest.setPackageName(moduleInfo.manifest.moduleid);
manifest.replaceTiPlaceholdersUsing(this.tiapp, this.appid);
await manifest.writeToFilePath(path.join(debugDirPath, 'AndroidManifest.xml'));
await manifest.writeToFilePath(path.join(releaseDirPath, 'AndroidManifest.xml'));
Expand All @@ -2065,7 +2064,6 @@ AndroidBuilder.prototype.generateLibProjectForModule = async function generateLi
this.logger.error(`Unable to load Android <manifest/> content from: ${tiModuleXmlFilePath}`);
throw ex;
}
mainManifest.setPackageName(moduleInfo.manifest.moduleid);
await mainManifest.writeToFilePath(path.join(projectSrcMainDirPath, 'AndroidManifest.xml'));

// Generate a "build.gradle" file for this project from the SDK's "lib.build.gradle" EJS template.
Expand Down Expand Up @@ -2157,6 +2155,7 @@ AndroidBuilder.prototype.generateRootProjectFiles = async function generateRootP
gradleProperties.push({ key: 'android.useAndroidX', value: 'true' });
gradleProperties.push({ key: 'android.enableJetifier', value: 'true' });
gradleProperties.push({ key: 'android.suppressUnsupportedCompileSdk', value: '33' });
gradleProperties.push({ key: 'android.nonTransitiveRClass', value: 'false' });
gradleProperties.push({ key: 'org.gradle.jvmargs', value: `-Xmx${this.javacMaxMemory}` });
await gradlew.writeGradlePropertiesFile(gradleProperties);

Expand Down Expand Up @@ -3681,9 +3680,6 @@ AndroidBuilder.prototype.generateAndroidManifest = async function generateAndroi

// Write secondary "AndroidManifest.xml" if not empty.
if (!secondaryManifest.isEmpty()) {
// Make sure package name is set in <manifest/> so that ".ClassName" references in XML can be resolved.
secondaryManifest.setPackageName(this.appid);

// Replace ${tiapp.properties['key']} placeholders in manifest.
secondaryManifest.replaceTiPlaceholdersUsing(this.tiapp, this.appid);

Expand Down
6 changes: 0 additions & 6 deletions android/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,6 @@ AndroidModuleBuilder.prototype.generateModuleProject = async function generateMo
this.logger.error('Unable to load Android <manifest/> content from "timodule.xml" file.');
throw err;
}
let packageName = moduleId;

This comment has been minimized.

Copy link
@prashantsaini1

prashantsaini1 Sep 23, 2024

Contributor

Cannot build app using latest master.

I believe this is breaking apps which includes modules like com.alcoapps.actionbarextras, bencoding.securely, etc.

Error logs:

[INFO]  Generating main "AndroidManifest.xml" files
[INFO]  Building app
[ERROR] [GRADLE] 
[ERROR] [GRADLE] FAILURE: Build failed with an exception.
[ERROR] [GRADLE] 
[ERROR] [GRADLE] * What went wrong:
[ERROR] [GRADLE] A problem occurred configuring project ':lib.com.alcoapps.actionbarextras'.
[ERROR] [GRADLE] > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
[ERROR] [GRADLE]    > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
[ERROR] [GRADLE]      
[ERROR] [GRADLE]      If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
[ERROR] [GRADLE] 
[ERROR] [GRADLE] * Try:
[ERROR] [GRADLE] > Run with --stacktrace option to get the stack trace.
[ERROR] [GRADLE] > Run with --info or --debug option to get more log output.
[ERROR] [GRADLE] > Run with --scan to get full insights.
[ERROR] [GRADLE] > Get more help at https://help.gradle.org.
[ERROR] [GRADLE] 
[ERROR] [GRADLE] BUILD FAILED in 780ms
[ERROR] "gradlew" tool returned exit code: 1
if (packageName.indexOf('.') < 0) {
packageName = `ti.${packageName}`;
}
mainManifest.setPackageName(packageName);
await mainManifest.writeToFilePath(path.join(moduleMainDir, 'AndroidManifest.xml'));

// Generate Java file used to provide this module's JS source code to Titanium's JS runtime.
let fileContent = await fs.readFile(path.join(this.moduleTemplateDir, 'CommonJsSourceProvider.java'));
Expand Down
3 changes: 0 additions & 3 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ org.gradle.jvmargs=-Xmx1536m
# Note: Jetifier is not needed for test app since it doesn't use Google's deprecated support libraries.
android.useAndroidX=true
android.enableJetifier=false

# remove if com.android.tools.build:gradle can be raised in /android/build.gradle
android.suppressUnsupportedCompileSdk=33,34
3 changes: 2 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Tue Mar 19 21:28:34 EET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 5 additions & 2 deletions android/kroll-apt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

// Checks our Java code against our style guidelines and for common coding mistakes using "checkstyle.xml".
// Will trigger a build failure if any violations have been detected.
Expand Down Expand Up @@ -55,6 +57,7 @@ tasks.withType(JavaCompile).configureEach {
// building with JDK newer than the Java version we're targeting. (Ex: Build with JDK 8, but target Java 7.)
// Note: Build tool wants a reference to runtime JAR of the same version we're targeting. Not going to happen.
options.compilerArgs << '-Xlint:-options'
options.incremental = true
}

// Bundle the below library dependencies within this project's built JAR.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

import org.json.simple.JSONValue;

@SupportedSourceVersion(SourceVersion.RELEASE_11)
@SupportedSourceVersion(SourceVersion.RELEASE_17)
@SuppressWarnings("unchecked")
@SupportedAnnotationTypes({
KrollJSONGenerator.Kroll_argument,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.appcelerator.kroll.annotations.generator.KrollJSONGenerator,dynamic
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.timepicker.MaterialTimePicker;
import com.google.android.material.timepicker.TimeFormat;
import com.google.android.material.R;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.R;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import com.google.android.material.color.MaterialColors;
import java.lang.ref.WeakReference;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.R;
import org.appcelerator.titanium.util.TiExifOrientation;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.util.TiColorHelper;
import ti.modules.titanium.media.MediaModule;
import com.google.android.material.R;

public class TiImageView extends ViewGroup
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.R;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;
import com.google.android.material.R;

public class TiUIActivityIndicator extends TiUIView
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import androidx.appcompat.widget.AppCompatButton;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.R;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.R;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr

// Create a button with given settings and add it to view group.
Context context = buttonGroup.getContext();
int attributeId = R.attr.materialButtonOutlinedStyle;
int attributeId = com.google.android.material.R.attr.materialButtonOutlinedStyle;
if (title.isEmpty() && (imageDrawable != null)) {
context = new ContextThemeWrapper(context, R.style.Widget_Titanium_OutlinedButton_IconOnly);
attributeId = R.attr.materialButtonToggleGroupStyle;
attributeId = com.google.android.material.R.attr.materialButtonToggleGroupStyle;
}
MaterialButton button = new MaterialButton(context, null, attributeId);
button.setText(title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr

// Create a button with given settings and add it to view group.
Context context = buttonGroup.getContext();
int attributeId = R.attr.materialButtonOutlinedStyle;
int attributeId = com.google.android.material.R.attr.materialButtonOutlinedStyle;
if (title.isEmpty() && (imageDrawable != null)) {
context = new ContextThemeWrapper(context, R.style.Widget_Titanium_OutlinedButton_IconOnly);
attributeId = R.attr.materialButtonToggleGroupStyle;
attributeId = com.google.android.material.R.attr.materialButtonToggleGroupStyle;
}
MaterialButton button = new MaterialButton(context, null, attributeId);
button.setEnabled(isEnabled);
Expand All @@ -217,8 +217,8 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr
new int[] { android.R.attr.state_checked },
},
new int[] {
oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface),
col
oldColors.getColorForState(new int[] { -android.R.attr.state_checked },
com.google.android.material.R.attr.colorOnSurface), col
}
);
button.setBackgroundTintList(trackStates);
Expand All @@ -232,8 +232,8 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr
new int[] { android.R.attr.state_checked },
},
new int[] {
oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface),
col
oldColors.getColorForState(new int[] { -android.R.attr.state_checked },
com.google.android.material.R.attr.colorOnSurface), col
}
);
button.setStrokeColor(trackStates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,6 @@ private int getTabCount()
@ColorInt
private static int getTabRippleColorFrom(Context context)
{
return MaterialColors.getColor(context, R.attr.colorPrimary, Color.DKGRAY);
return MaterialColors.getColor(context, com.google.android.material.R.attr.colorPrimary, Color.DKGRAY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.R;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
Expand Down Expand Up @@ -57,6 +56,7 @@
import android.widget.TextView.OnEditorActionListener;
import androidx.appcompat.view.ContextThemeWrapper;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.R;

public class TiUIText extends TiUIView implements TextWatcher, OnEditorActionListener, OnFocusChangeListener
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public TiRecyclerViewHolder(final Context context, final ViewGroup viewGroup)
{
super(viewGroup);

COLOR_NORMAL = MaterialColors.getColor(context, R.attr.colorButtonNormal, Color.DKGRAY);
COLOR_PRIMARY = MaterialColors.getColor(context, R.attr.colorPrimary, Color.DKGRAY);
COLOR_NORMAL = MaterialColors.getColor(context, com.google.android.material
.R.attr.colorButtonNormal, Color.DKGRAY);
COLOR_PRIMARY = MaterialColors.getColor(context, com.google.android.material.R.attr.colorPrimary, Color.DKGRAY);
COLOR_SELECTED = ColorUtils.setAlphaComponent(COLOR_PRIMARY, 20);

if (resources == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import androidx.appcompat.widget.SearchView;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.R;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.UIModule;
import com.google.android.material.R;

public class TiUISearchBar extends TiUIView
{
Expand Down
Loading

0 comments on commit 50d8604

Please sign in to comment.