AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Delphi-PRAXiS - Lounge Delphi-News aus aller Welt RAD Studio 10.3 Rio’s Android Intent support (or current lack thereof)
Thema durchsuchen
Ansicht
Themen-Optionen

RAD Studio 10.3 Rio’s Android Intent support (or current lack thereof)

Ein Thema von DP News-Robot · begonnen am 8. Dez 2018
Antwort Antwort
Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
15.411 Beiträge
 
#1

RAD Studio 10.3 Rio’s Android Intent support (or current lack thereof)

  Alt 8. Dez 2018, 21:40
Sometimes when a new product is released there are a few ‘teething issues’. That certainly seems to be the case with RAD Studio 10.3 Rio. Both Delphi and C++Builder are hitting a few problems on various fronts. Now, it is true that internally in the product there has been a lot of change in the IDE, the VCL and FireMonkey, and perhaps it is therefore unsurprising a few slip-ups will have occurred, It is, however, quite annoying when you fall foul of these slip-ups and have to wait for a fix….

The issue I want to address in this post is the breakage in the Android support for registering an interest in knowing about certain Intent objects received by the app. This is normally achieved by a call to MainActivity.registerIntentAction, as pseudo-documented here (when it was introduced in RAD Studio 10 Seattle) and here (in reference to a sample app) on Embarcadero's docwiki and illustrated here in my article on NFC usage.

This new Intent support worked nicely in RAD Studio 10 Seattle, 10.1 Berlin and 10.2 Tokyo. Not so in RAD Studio 10.3 Rio. You get a crash when trying to register a new Intent that you want to act upon.

This issue has already been reported twice, once here as RSP-21841 and again here as RSP-22877. I’ve had direct contact from someone using my NFC ode who has hit this problem. The cause of the problem was an oversight in a change made to the Java code underlying the FMX Android integration during a refactoring exercise. This is highlighted in the RSP-21841 report by Dave Nottage.

In short an array used to hold the list of registered [FONT=Courier New]Intent[/FONT]s is now set up as an immutable array instead of a mutable array and this leads to the following unsavoury response to any call to [FONT=Courier New]MainActivity.registerIntentAction[/FONT]:



So, while we await an official fix for this can we generate an unofficial fix? Yes! And what’s more it doesn’t take much effort.

The steps below assume a default installation with default folders and so on. You’ll need to change any folders that you customised.

1) First things first, download and install Code Central download 30869: December 2018 Missing Files Patch for 10.3. That then gives is the full set of Android Java files within RAD Studio.

Now we are going to correct the error and rebuild fmx.jar and fmx.dex.jar, which contain the errant code.

2) Make a backup of fmx.jar and fmx.dex.jar from these two folders (so 4 files in total being backed up):
  • C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug
  • C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\release
The next step is to fix the broken Java source code. The source file in question is in the Program Files (x86) folder tree and so can’t be edited normally. You need to run a text editor (for example RAD Studio or Notepad++) as administrator in order to be allowed to do that.

3) Anyway, open up C:\Program Files (x86)\Embarcadero\Studio\20.0\source\rtl\androidde x\java\fmx\src\com\embarcadero\firemonkey\FMXNativ eActivity.java.

3a) Now locate the declaration of the field mRegisteredIntentActions, which is currently declared and (wrongly) initialised like this:

private List mRegisteredIntentActions = Arrays.asList(
NotificationInfo.ACTION_NOTIFICATION,
NotificationPublisher.ACTION_GCM_NOTIFICATION);

Change this to:

private List mRegisteredIntentActions = new java.util.ArrayList();

3b) Next find where the onCreate method calls it inherited version with this statement:

super.onCreate(savedInstanceState);

Precede that with these two statements:

mRegisteredIntentActions.add(NotificationInfo.ACTI ON_NOTIFICATION);
mRegisteredIntentActions.add(NotificationPublisher .ACTION_GCM_NOTIFICATION);

That’s the code sorted out.

4) Now that’s done you should save the batch script shown at the end of this post in a text file somewhere (it doesn’t matter where) called BuildFMX.bat. Note that it’s important to ensure the file is stored as either a .bat file or a .cmd file if you prefer – if your Windows File Explorer is still left with its default options you won’t see file extensions and it’s easy to go wrong… I’ll work on the assumption you have saved it into a folder called C:\Scripts as C:\Scripts\BuildFMX.bat

5) The final job is to run the batch file BuildFMX.bat. Since it needs to generate and update files in the protected Program Files (x86) folder you will need to run up an administrative command prompt. The easiest way to do this is to press the Windows key ([FONT=Wingdings][SIZE=3]ÿ[/SIZE][/FONT]), type cmd and press Ctrl+Shift+Enter. This will run cmd.exe as Administrator.

Change to the folder where you stored the batch file, e.g.:

cd C:\Scripts

Now run the script:

BuildFMX

You should see this:



Here’s the batch script to be saved into a batch file:

@echo off
cls

setlocal enabledelayedexpansion

rem Set environment variables - check these folders match your setup

set BDS=%ProgramFiles(x86)%\Embarcadero\Studio\20.0
set JAVA_PATH=%ProgramFiles%\Java\jdk1.8.0_60\bin
set SDK_PATH=%PUBLIC%\Documents\Embarcadero\Studio\20. 0\PlatformSDKs\android-sdk-windows

rem Set more environment variables based on those above

set DX_PATH=%SDK_PATH%\build-tools\28.0.2
set ANDROID_JAR=%SDK_PATH%\platforms\android-26\android.jar
set BDS_LIB=%BDS%\lib
set BDS_DEBUG_LIB=%BDS%\lib\android\debug
set BDS_RELEASE_LIB=%BDS%\lib\android\release
set FMX_SRC_PATH=%BDS%\source\rtl\androiddex\java\fmx
set CLASS_PATH=%ANDROID_JAR%
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\android-support-v4.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\cloud-messaging.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\google-play-services-base-7.0.0.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\google-play-services-maps-7.0.0.jar
set CLASS_PATH=%CLASS_PATH%;%BDS_DEBUG_LIB%\google-play-services-ads-7.0.0.jar

echo.
echo Changing to the FMX source folder
echo.

pushd %FMX_SRC_PATH%

echo Getting fully qualified list of all Java source file we need to rebuild
echo.

if not exist bin\classes mkdir bin\classes
if not exist bin\debug mkdir bin\debug
if not exist bin\release mkdir bin\release
dir src\android\bluetooth\*.java /s /b > JavaSources.txt
dir src\android\telephony\*.java /s /b >> JavaSources.txt
dir src\com\*.java /s /b >> JavaSources.txt

echo Ensuring FMX source path ends in a '\'
echo.

set LAST_CHAR=%FMX_SRC_PATH:~-1%
if not "%LAST_CHAR%"=="\" set FMX_SRC_PATH=%FMX_SRC_PATH%\

echo Making Java source file paths relative to current directory
echo.

if exist JavaSources2.txt del JavaSources2.txt
for /F "tokens=*" %%A in (JavaSources.txt) do (
set STR=%%A
call set string=%%STR:!FMX_SRC_PATH!=%%
call echo !string! >> JavaSources2.txt
)

echo Compiling all the FMX Java code into class files with debug info
echo.

"%JAVA_PATH%"\javac -d bin\classes -nowarn -classpath "%CLASS_PATH%" -encoding UTF-8 -target 1.5 -g -source 1.5 @JavaSources2.txt
if errorlevel 1 (
echo.
echo Problem encountered during Java compilation
goto :Error
)

echo.
echo Creating jar containing the new compiled FMX Java classes with debug info
echo.

"%JAVA_PATH%"\jar cf bin\debug\fmx.jar -C bin\classes .
if errorlevel 1 (
echo.
echo Problem encountered during Java archiving
goto :Error
)

echo Creating DEX jar containing the new compiled FMX Java classes with debug info
echo.

call %DX_PATH%\dx --dex --output=bin\debug\fmx.dex.jar --positions=lines bin\debug\fmx.jar
if errorlevel 1 (
echo.
echo Problem encountered during DEXing
goto :Error
)

echo Compiling all the FMX Java code into class files without debug info
echo.

"%JAVA_PATH%"\javac -d bin\classes -nowarn -classpath "%CLASS_PATH%" -encoding UTF-8 -target 1.5 -source 1.5 @JavaSources2.txt
if errorlevel 1 (
echo.
echo Problem encountered during Java compilation
goto :Error
)

echo.
echo Creating jar containing the new compiled FMX Java classes without debug info
echo.

"%JAVA_PATH%"\jar cf bin\release\fmx.jar -C bin\classes .
if errorlevel 1 (
echo.
echo Problem encountered during Java archiving
goto :Error
)

echo Creating DEX jar containing the new compiled FMX Java classes without debug info
echo.

call %DX_PATH%\dx --dex --output=bin\release\fmx.dex.jar --positions=lines bin\release\fmx.jar
if errorlevel 1 (
echo.
echo Problem encountered during DEXing
goto :Error
)

copy bin\debug\* "%BDS_DEBUG_LIB%"
copy bin\release\* "%BDS_RELEASE_LIB%"

echo Tidying up...
echo.
if exist JavaSources.txt del JavaSources.txt
if exist JavaSources2.txt del JavaSources2.txt
rd /s /q bin

goto :End

:Error
echo.
echo Sorry, we had a problem :(

:End

echo Changing back to the folder we started in

popd

endlocal


Weiterlesen...
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:15 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz