Building a asset pack in a Ionic project in Android studio - android-gradle-plugin

I have recently converted my only cordova project to use Ionic and Capacitor.
Publishing to the app store I find my app is too big (in the aab format), because I have too many images.
I understand I need to create an asset pack. All I can find about the details of a creating an asset pack is https://developer.android.com/guide/playcore/asset-delivery/integrate-native
(anyone have any better information?).
After following those steps, in VS Code I ...
> ionic build
> ionic capacitor build
Then in Android studio I do.
Menu | Build | Make Project
I get the following error:
Build file 'C:\code\myco-match\android\build.gradle' line: 27
A problem occurred evaluating root project 'android'.
> Could not find method android() for arguments [build_19eh0vogqj489iczcfbatfj08$_run_closure2#69641835] on root project 'android' of type org.gradle.api.Project.
Line 27 is
android {
assetPacks = [":species-images"]
}
Did I leave out a step in the build?
Am I missing something in my gradle configuration? I am not that familiar with gradle).
Did I forget something in my initial app conversion? It was my 1st cordova project converted to my 1st ionic and capacitor project.
Any ideas?

The problem is that in the reference in my first link above I mis-read step 2.
https://developer.android.com/guide/playcore/asset-delivery/integrate-native
Reading the following stack overflow issue
Gradle sync failed: Could not find method android() for arguments on root project on android studio
Gabriele Mariotti said the poster "using the wrong build.gradle file.
You can't define the android block in the top-level file."
Reviewing the instructions step 4 says "In the project’s app build.gradle file"
I had incorrectly changed the top-level build.gradle file.
Step 7 lists build.gradle as if you change it, but that list item ought to be /app/build.gradle.
Now I can build and package using android studio.

Related

HelloWorld in Kotlin gives error "Could not find or load main class"

I spent the last 1,5 hour trying to make this simple tutorial work in IntelliJ IDEA, as you can see in this video.
When trying to run the code, I get the error:
/[...] -Dfile.encoding=UTF-8 src.HelloKt
Error: Could not find or load main class src.HelloKt
Caused by: java.lang.ClassNotFoundException: src.HelloKt
I have tried setting up SDK, invalidating cache, removing .idea and .gradle, rebuilding project, deleting the profile and adding it again. I tried those actions in different orders.
Here's a screenshot of the project:
It also complains Kotlin is not configured, but I have already configured it.
Here's the run configuration:
Here are the project settings:
Your Hello.kt file needs to be somewhere inside the src/main folder, probably in src/main/kotlin. This is different from the tutorial, because your project is using Gradle, and the one in the tutorial isn't. I think this is because newer versions of IntelliJ use Gradle by default for new projects, which wasn't the case when the tutorial was written.
The use of src/main/kotlin and src/test/kotlin as source code directories is a convention in Gradle (and Maven). When importing a Gradle project into IntelliJ, main becomes a module, and kotlin becomes a source folder within that module. The same goes for test. In your screenshots, the bold text and blue icons on main and test confirm that's how your project is set up. Files outside of those folders aren't treated as source files, which explains why your Hello.kt file isn't being compiled or recognised correctly.
It's likely that the default behaviour of IntelliJ when creating a new project has changed since this tutorial was written. In the tutorial, they select "Kotlin" as the project type and this creates a project that doesn't use Gradle. As a result, the project doesn't use the src/main/kotlin directory structure.
I can see from your video that you selected the same option, but on the next screen, IntelliJ still automatically selected Gradle as the build system for the new project. To match the project structure used in the tutorial, I think you would need to select "IntelliJ" as the build system.

Kotlin - Application project template - error main class not found

I am using IntelliJ IDEA 2021.1 (Community Edition) - Build #IC-211.6693.111, built on April 6, 2021.
I created a new kotlin project - project template(JVM): Application, built system: Gradle Kotlin,
project JDK:1.8 version 1.8.0_281.
In the “scr/main/kotlin” folder, I created a kotlin file with a simple code like "fun main(){println(“Hi!”)}.
When I tried to run the file(the build was ok), I got this error: “Could not find or load main class MyAppKt”.
What did I do wrong?
Did you also add your main class to the build.gradle file?
mainClassName = "projectPackage.MyAppKt"
I assume if you are adding the MyAppKt file manually it is not added to the build.grale. But clearly more information about the project would help here. Meanwhile check this post Kotlin - Error: Could not find or load main class _DefaultPackage

react native linking a library to inside the another library

Is it possible to link a library which has native dependencies inside another library? Trying to find the solution to link manually, but failing to do it so. I found a [question]: Using React-Native library inside another React-Native library summary, saying It is not possible to add/link a library to another library.
Is there any manual way to do this or not possible?
[Edit]
Trying to add the react-native-spring-scrollview: ^2.0.20 library to my library react-native-demolibrary, which is a library created using react-native-create-library command, since it is a library there were no settings.gradle file. So created and tried to link manually library to react-native-somelibrary.
settings.gradle
include ':react-native-spring-scrollview'
project(':react-native-spring-scrollview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-spring-scrollview/android')
build.gradle
implementation project(':react-native-spring-scrollview')
below error has shown up,
GRADLE CONSOLE ERROR
org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Build file 'E:\Workspace\DemoApp\node_modules\react-native-demolibrary\android\build.gradle' line: 37
A problem occurred evaluating project ':react-native-library'.
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:139)
at org.gradle.initialization.DefaultGradleLauncher.getConfiguredBuild(DefaultGradleLauncher.java:104)
at .....more
ERROR:
Project with path ':react-native-spring-scrollview' could not be found in project ':react-native-demolibrary'.
Open File
Thank you in advance.

How to use square dagger-compiler for "compile-only" using gradle?

Currently I have my dagger dependencies declared like this:
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.squareup.dagger:dagger-compiler:1.2.1'
I don't want dagger-compiler to be included to my Android apk since it also adds Guava dependency, which is big and break Android 65K limit for our app.
I saw that in maven projects dagger-compiler is added as "provided", but I failed to find anything similar for gradle android build.
There exists a provided keyword:
compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
Heres a sample build.gradle: volley-examples
The provided scope is supported in Android-Gradle/Android Studio. You can get at it through the UI in Project Structure > Dependencies, or you can use the provided keyword instead of compile in your build files if you want to edit them by hand.

where is gradle storing the android buildapk?

I use the command gradle clean build
it ends with BUILD SUCCESSFUL, but where can I find the build .apk?
Or how can I set up the build directory destination?
Look in //build/apk. You'll need to do this outside of Android Studio since AS filters the directories and hides "apk".
Update: Android Studio no longer filters the output directory, so you can just drill into the build directory (under the app).