KMM Project Build for iOS Without Running - android-studio

Maybe I'm just missing something but is there a way to trigger the iOS build in Android Studio for a KMM project that doesn't launch the simulator once the build is done?
When looking at the iosApp run configuration I see it has "Build iOS application" listed under "Before Launch" which makes me suspect this is possible but I didn't see it listed as a gradle task or anywhere else I could think of.
I've been doing the iOS work in Xcode and when I make changes to the shared code I want to rebuild it without running the app (which I've been doing from inside Xcode).

Not exactly a solution, but I found that when you hit build in Xcode it builds the Kotlin code so any changes to the shared module are included automatically. No need to do iOS builds from Android Studio.

Related

How to configure an iOS Application for Kotlin Multiplatform in Android Studio?

I want to add a Run/Debug Configuration for an iOS Application for a Kotlin Multiplatform Mobile application in Android Studio 4.1.2. However, there seems to be a problem with the configuration for iOS.
In the screenshot below you can see the problem. In the dialog "Run/Debug Configuration" Android Studio complains about
Error: Please specify Xcode project location in xcodeproj property of gradle.properties
Using the "Fix" button does not solve the problem. Android Studio just adds an additional xcodeproj to gradle.properties and the complains about a duplicate parameter.
I also tried different paths (relative and absolute) for xcodeproj. No luck.
If I remember correctly, it used to work out of the box. A new Kotlin Multiplatform Mobile project was automatically configured for Android and iOS. I'm not sure what changed. Probably something was updated.
Is this a bug with the KMM plugin? Or is there something I can do on my system to fix this?
don't do that with Android Studio.
Just open Xcode, click on 'open another project...', locate to the iosApp folder that named it when creating your project on Android Studio.
after that, just click run and have fun.
If the project doesn't run right away even on opening it from Xcode and shows the shared framework is missing, Then try generating the shared framework for iOS platform using terminal. Navigate to the project folder and execute
Command: ./gradlew packForXcode
Now the shared framework should have a xcode-frameworks product and you should be able to build and run the project through Xcode.
I fixed it by downgrading the Kotlin version from 1.4.30 to 1.4.21. You can check this thread here. To downgrade, download the version you want from the plugin store and choose the install plugin from disk as in the picture below
Upgrading Android Studio version to 4.2.1, KMM plugin version to 0.2.6, creating new KMM project with KMM plugin, the problem can be fixed automatically.
If you don't wanna use Xcode:
Look like there is some IDE issues in this versions, one option would be to downgrade the Kotlin version.
What worked for me was to download the latest Canary Android Studio and setup my KMM project there.
Hopefully soon this will be stable for the next versions
Same as here: https://stackoverflow.com/a/66941077/3117650
Look like there is some IDE issues in this versions, one option would be to downgrade the Kotlin version.
What worked for me was to download the latest Canary Android Studio and setup my KMM project there.
Hopefully soon this will be stable for the next versions

The difference between running tests from AndroidStudio and gradle task

I have local tests which use mockito and powerMockito in my project. There are about 300 of them.
When I run them from the Android Studio (Run -> Run test configuration), all of them passed.
But our CI system launch it using gradle task testDebugUnitTest, which fails about 90 of them with different errors.
The question is: what is the difference between these mechanisms?
Are you using Android Gradle(https://developer.android.com/studio/releases/gradle-plugin.html) plugin?
One must be aware that Android Studio build system is based on Gradle, and the Android plugin for Gradle adds several features that are specific to building Android apps. Although the Android plugin is typically updated in lock-step with Android Studio, the plugin (and the rest of the Gradle system) can run independent of Android Studio and be updated separately.
Official docs here: https://developer.android.com/studio/releases/gradle-plugin.html
So, if there are version and platform related differences, we should expect the results to be different.
Hope this helps!

Using Android Studio, Adding a Library to build.gradle

I'm using Android Studio, and I'm trying to add the slf4j library using
Build/Edit Libraries and Dependencies.
I clicked on the +, selected Library Dependency, and picked slf4j from the list. Studio added the library to my build.gradle file like this:
dependencies {
compile 'com.android.support:support-v4:24.1.1'
compile 'org.slf4j:slf4j-android:1.7.7'
...
But when I try to run sync, I get this error:
Error:(75, 10) Failed to resolve: org.slf4j:slf4j-android:1.7.7
Is there something else I need to do to my project to be able to use this library??
Turns out what was causing this issue for me (and likely for you, given the build file above) was the Scala plugin. There was a bug with the Scala plugin preventing Android Studio from importing Gradle projects. The fix for this has already been pushed live, so to get Android Studio working again you can either disable the Scala plugin or update it.
Open Settings/Preferences
Open the Plugins section on the left
Find the Scala plugin
Right click on the plugin and click Reload List of Plugins
Right click on the plugin again and click Update Plugin
This allowed me to do a Gradle sync and build from Android Studio again, I hope it helps for you!
It looks like this is a bug with Android Studio. Hopefully it'll be fixed soon.
In the meantime, you can debug your application without launching it from Android Studio by attaching the debugger to a running process of the application. You can do this two ways.
Via the menus: Run -> Attach Debugger to Android Process
Pressing the button that is two to the right of the play/build button. It looks like a grey phone/rectangle with a little green bug in the bottom right
After you do this, a dialog will show up listing available applications to debug. Select your application and press OK. Your breakpoints should now work.
If you need to debug something that happens on app startup, you can tell Android to wait for a debugger when launching certain applications with the following steps:
On the phone open the Android Settings
Open the Developer Options
Make sure Wait for debugger is checked
Press Select debug app and choose your application
Then when you start your application, it'll wait for you to attach a debugger via one of the two methods mentioned above.
Hope this helps!
In order to get the maven repository working with my Android Studio project (which I didn't know is what I was trying to do), I needed to add the following to build.gradle:
allprojects {
repositories {
mavenCentral()
}
}
Apparently, that allows the software to work out the compile commands.

Android Studio avoid "make" while running

When you press the run button in Android Studio the project is buit again, and as you know this always take long, if e.g. I select Build -> Make Project and then "Run" the make process runs again, I don't understand why? I would expect that it only installs the APK that is already generated. Is there a way I can achieve this, is my expectation funded or am I thinking wrong?
I've used the approach described here to speedup my build.
Building and running app via Gradle and Android Studio is slower than via Eclipse
At the same time i've disabled "make project automatically" because sometime it produces old code.

INSTALL_FAILED_DEXOPT zip archive does not include classes.dex

I've been struggling with this problem for 2 days. I can't debug my application on my android device using Android Studio.
This is the error I get:
[INSTALL_FAILED_DEXOPT]
When I look at the logs, it says "zip archive does not include classes.dex"
So the problem is that classes.dex isn't being built into the APK. This is true since the file size of my APK is now around 1MB whereas it used to be around 1.3MB.
I have tried everything, but I have no idea why classes.dex isn't being built into my APK. Any help is greatly appreciated.
Joaquin
Try cleaning your build, and build the app again.. Make sure you've added the activities to the Android manifest. Once you get the apk use 7zip to view apk and check if there is classes.dex or use native zip viewer if on Linux. And if nothing still works try synchronizing the build files so that gradle can detect non ide changes.
I just tried disabling my antivirus (Avast), cleaning and rebuilding the app and then restarting Android Studio.
Those steps worked and I can now debug my application on my android device again.
Note that classes.dex is only generated if your project contains Java classes. So if you are using the NDK in combination with native activities, there won't be no Java code at all and therefore no classes.dex. In that case, you have to set the hasCode attribute in the manifest to false because otherwise dexopt will be looking for it.
http://developer.android.com/guide/topics/manifest/application-element.html#code

Resources