ionic5 compiling for android problems

Posted on Updated on

One of the most annoying thing about Ionic is chasing your tail.

Things don’t always w2ork as expected. You have to install JavaSDK, Gradle, maybe CocoaPods, tools.jar, and more.

This tool me hours to find the solution:

No installed build tools found. Install the Android build tools version 19.1.0 or higher.
I found the answer here:

https://stackoverflow.com/a/61572984/1190051

The next problem was this:

"Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation."

I found a solution from here: https://stackoverflow.com/a/65211651/1190051

Here is my output:

stephenmonro@SMMMacMini c4i2021 % /usr/libexec/java_home -V | grep jdk
 Matching Java Virtual Machines (3):
 1.8.281.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
 1.8.0_281 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
 1.8.0_171 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
 stephenmonro@SMMMacMini c4i2021 %

The example went like this:

I used the command /usr/libexec/java_home -V | grep jdk Cristian Gomez provided, got two paths:

Matching Java Virtual Machines (2):
1.8.181.13 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_111 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
Changing the .zshrc did not solve the problem.
Finally I copied tools.jar in /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/lib/ to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ and solved the problem.

Now, to solve the next problem with signing, which should be too hard as well.

Another problem when it wouldn’t compile with the following error:

Task :app:compileDebugJavaWithJavac FAILED
 \platforms\android\app\src\main\java\com\ionicframework\cordova\webview\IonicWebViewEngine.java:11: error: package android.support.annotation does not exist
 import android.support.annotation.RequiresApi;
                              ^
 \platforms\android\app\src\main\java\com\ionicframework\cordova\webview\IonicWebViewEngine.java:137: error: cannot find symbol
 @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
  ^
 symbol:   class RequiresApi
 location: class IonicWebViewEngine.ServerClient
 Note: Some input files use or override a deprecated API.
 Note: Recompile with -Xlint:deprecation for details.
 2 errors

You’ll need to install this plugin:

ionic cordova plugin add cordova-plugin-androidx-adapter

Another problem was this:

in/res/drawable-land-hdpi/screen.png: Error: The drawable "screen" in drawable-land-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]

This was solved by this post

Add this in your config.xml under android

<splash density="ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
<splash density="mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
<splash density="hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
<splash density="xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
<splash density="xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
<splash density="xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />

One of the bigger things I’ve been noticing with some of the other errors I’m getting, is that once you find the line in code that it failed on, you just do a search, and in this above case, it’s CDVFileTransfer.m

That is the Ionic File Transfer

Just run these two commands associated with that plugin thing, and it then seems to work (until the next error):

ionic cordova plugin add cordova-plugin-file-transfer
npm install @ionic-native/file-transfer

This happens with many of the error 65 problems.

Actually, in this case – a good example of things that don’t always work… I wrote this before succeeding.

However, in the case of the above problem, it didn’t work at all, and so I had to abandon using File-Transfer. Instead, I am now using File-Saver which is half the code and seems to work for PDF files.

I also removed the file-transfer plugins too.

$ ionic cordova plugin remove cordova-plugin-file-transfer
$ npm uninstall @ionic-native/file-transfer

Yet another error. This happens when opening PDFs via the above method:

ERROR Internal navigation rejected – not set for url=’blob:ionic://localhost/ etc

Adding this in the config.xml allows for the opening of the PDF, however it then breaks the app, because if basically opens in an internal webrowser or something weird.

  <allow-navigation href="*" /> 

Stay tuned for a fix...

Yeah, scrap that last stuff. Just use a link like this:

<a style="text-decoration:none;" target="_system" [href]="item.url" [innerHTML]="item.title_date"></a>  

Or try this solution: https://ovpv.me/open-pdf-ionic-4/

 download(url: string, title: string) 
 {

  //// 'hybrid' detects both Cordova and Capacitor
  if (this.platform.is('hybrid')) 
  {
    this.fileTransfer = this.transfer.create();
    this.fileTransfer
    .download(url, this.file.dataDirectory + title + ".pdf")
    .then(entry => {
    console.log("download complete: " + entry.toURL());
    this.fileOpener
    .open(entry.toURL(), "application/pdf")
    .then(() => console.log("File is opened"))
    .catch(e => console.log("Error opening file", e));
    });
  
  }else{
    window.open(url,'_blank');
  }

}

This is still the error:

86_64/CDVConnection.o

** BUILD FAILED **

The following build commands failed:
CompileC /Users/stephenmonro/Library/Developer/Xcode/DerivedData/Christians_for_Israel-dkgqzlaztjythbaawmdqxxnhjikl/Build/Intermediates.noindex/Christians\ for\ Israel.build/Release-iphonesimulator/Christians\ for\ Israel.build/Objects-normal/x86_64/CDVFileTransfer.o /Users/stephenmonro/ionicApps/c4i2021/c4i2021/platforms/ios/Christians\ for\ Israel/Plugins/cordova-plugin-file-transfer/CDVFileTransfer.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
Command finished with error code 65: xcodebuild -workspace,Christians for Israel.xcworkspace,-scheme,Christians for Israel,-configuration,Release,-sdk,iphonesimulator,-destination,platform=iOS Simulator,name=iPhone 12 Pro Max,build,CONFIGURATION_BUILD_DIR=/Users/stephenmonro/ionicApps/c4i2021/c4i2021/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/stephenmonro/ionicApps/c4i2021/c4i2021/platforms/ios/build/sharedpch
xcodebuild: Command failed with exit code 65
Error: xcodebuild: Command failed with exit code 65
at ChildProcess.whenDone (/Users/stephenmonro/ionicApps/c4i2021/c4i2021/node_modules/cordova-common/src/superspawn.js:136:25)
at ChildProcess.emit (events.js:189:13)
at maybeClose (internal/child_process.js:970:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
[ERROR] An error occurred while running subprocess cordova.

    cordova build ios --release --verbose exited with exit code 65.

    Re-running this command with the --verbose flag may provide more information.

ionic:utils-process onBeforeExit handler: ‘process.exit’ received +0ms
ionic:utils-process onBeforeExit handler: running 2 functions +0ms
ionic:utils-process processExit: exiting (exit code: 65) +36ms

Surprisingly, this worked: https://forum.ionicframework.com/t/error-in-ios-build-with-cordova-plugins/197881/3

So many problems. So many problems! There is usually a fix somewhere though. You just have to find it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s