Converting existing Flutter Java Android project to Kotlin - java

I have an existing Flutter project that was created with Android Java set.
I tried removing my android directory and running flutter create -a kotlin .. App fails to run and error says it is still expecting main/java/com/myApp/MainActivity.java even though the main/kotlin/com/myApp/MainActivity.kt was generated. Any ideas?

In your android app level, check your build.gradle and make sure you have this
android {
...
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
...
}
you can change the dir path to your MainActivity.kt placed

Related

GStreamer Android Tutorial Build Failed

I'm running into number of problems while trying to run GStreamer Android Tutorials on Windows. I'am new to Android NDK so this could be a really simple issue but I couldn't figure out how to solve it.
These are the build error messages when I try to build the project
Build command failed.
Error while executing process
D:\gstreamer\android-ndk-r19b-windows-x86_64\android-ndk-r19b\ndk-build.cmd
with arguments {NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\jni\Android.mk
NDK_APPLICATION_MK=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\jni\Application.mk
APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0
APP_PLATFORM=android-16
NDK_OUT=C:/xxx/xxx/gst-docs-master/examples/tutorials/android/android-tutorial-1/build/intermediates/ndkBuild/release/obj
NDK_LIBS_OUT=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\build\intermediates\ndkBuild\release\lib
NDK_APPLICATION_MK=jni/Application.mk GSTREAMER_JAVA_SRC_DIR=src
GSTREAMER_ROOT_ANDROID=D:/gstreamer/gstreamer-1.0-android-universal-1.15.1
GSTREAMER_ASSETS_DIR=src/assets APP_SHORT_COMMANDS=false
LOCAL_SHORT_COMMANDS=false -B -n}
process_begin: CreateProcess(NULL, "", ...) failed.
*** Android NDK: Assertion failure: SYSROOT_LINK is not defined . Stop. Open File
When I clicked the "Open File" it has sent me to gstreamer-1.0.mk file and the lines below.
ifdef SYSROOT
SYSROOT_GST_INC := $(SYSROOT)
SYSROOT_GST_LINK := $(SYSROOT)
else
ifdef SYSROOT_INC
$(call assert-defined, SYSROOT_LINK)
ifdef SYSROOT_LINK
SYSROOT_GST_INC := $(SYSROOT_INC)
SYSROOT_GST_LINK := $(SYSROOT_LINK)
endif
else
SYSROOT_GST_INC := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH)
SYSROOT_GST_LINK := $(SYSROOT_GST_INC)
endif endif
I think the problem is about SYS_ROOT as mentioned in the error message but I don't know what "SYS_ROOT" means or "NDK_PROJECT_PATH" is.
I have added gstAndroidRoot to gradle.properties so while building this won't be a problem.
For Windows 10, Android Studio 3.5. This worked for me.
Download the entire gstreamer android studio tutorial directory from here.
Open Android Studio -> Open an existing Android Studio Project
Open the entire android tutorial directory examples/tutorials/android as a project
Once the project is open change the view on the left side of the screen to Project
Right click near local.properties. Right click -> file -> New -> File
Create a new file called gradle.properties
In the new gradle.properties file copy and paste the below code.
# gstAndroidRoot can be set to point to the unpacked GStreamer android top-level directory
# containing each architecture in subdirectories, or else set the GSTREAMER_ROOT_ANDROID
# environment variable to that location
gstAndroidRoot=/gstreamer_android_binaries
Note: Change the gstAndroidRoot variable to your file path where you downloaded the gstreamer binaries and unzipped them. Gstreamer can be downloaded from here for Android.
Now we need to set up NDK directory. Make sure you download and have NDK enabled under SDK tools.
This will download the latest NDK version. However gstreamer currently will not build with the latest NDK. We need to download NDK Revision 18b from here. If you do not use NDK version 18 you will likely get an error Android NDK: Assertion failure: SYSROOT_LINK is not defined . Stop. Open File
Unzip the downloaded NDK 18b directory.
Take the unzipped android-ndk-r18b directory and move it to where the ndk folder is under AppData\Local\Android\Sdk\ndk
You should now have two folders within Android\Sdk\ndk. 20.0.5594570 (or latest version) and android-ndk-r18b
In android studio go to File -> project Structure
Under Android NDK location point to the NDK 18 directory. Example: C:\Users\AppData\Local\Android\Sdk\ndk\android-ndk-r18b
Connect a phone with USB debugging and run!
If you get an error on the phone stating it is for an older version of android. Go back to Android Studio and switch to Android View on the left side of the screen. Under Gradle Scripts select the build.gradle for the appropriate tutorial. Change the compileSdkVersion 29, minSDKVersion 15, and targetSDKVersion 29.

Creating test folders in legacy Android Studio project

I've been having issues getting test folders adding to my existing legacy project. I've been looking through Stack and whilst these users are all having similar issues, the solutions haven't yet worked. I'm new at working with gradle, so this has been a bit confusing.
How to add test folders to an older Android Studio Project
Android studio doesn't recognise source folders
Cannot Create Testing Folders In Android Studio
The problem can be seen below:
When looking at android view, I get this.
You can see that there's a visible alpha and main folder.
Looking at project view, you can see the addition of the src/test/java and src/androidTest/java to the folder structure, but I can't get them to register in Android view.
I've tried setting the sourceSets in the gradle file:
sourceSets {
beta {
java.srcDirs = [ 'src/general/java']
res.srcDirs=['src/general/res']
}
general {
java.srcDirs = [ 'src/general/java', 'src/androidTest/java/', 'src/test/java']
res.srcDirs=['src/general/res']
}
demo {
java.srcDirs = [ 'src/alpha/java']
res.srcDirs=['src/alpha/res']
}
alpha {
java.srcDirs = [ 'src/alpha/java', 'src/androidTest/java/', 'src/test/java']
res.srcDirs=['src/alpha/res']
}
test {
java.srcDirs = ['src/test/java']
}
androidTest {
java.srcDirs = ['src/androidTest/java']
}
}
where test and androidTest are new. (Note: the others all have buildflavors associated with them, and I haven't created any for the tests. Could this be the issue?)
Some of the previous suggestions have said it's to do with build version and that there should be a testing related dropdown - here. I've tested all of the builds with no success.
Another user suggested using the build task assembleAndroidTest to generate the folders, which gives the following error:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':library:processDebugAndroidTestResources'.
Android resource linking failed
I've been having other issues with trying to get testing working whilst following through google's recommended documentation. Dependencies and manifest declarations have worked fine but trying to add
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
I get
Error:Unable to find optional library: android.test.runner
Which I've seen referenced for apache legacy but little for this situation. I think this is probably a different problem but included it in case it was relevant.
Android studio is at version 3.2.1.
So in summary:
How do I add test folders to the project and get them to display in Android view?
Thanks.
I found the problem. A simple fix.
Inside the main, the folder structure was
main/java/com/windowmaker/measure
and the folder structure for my test folders was
test/java
By changing the path to
test/java/com/windowmaker/measure
it now displays correctly.
Hooray!

How to change the package name of an Android flavor app with Gradle?

I am currently migrating a very old Android app from Eclipse to Android Studio.
In the old version of my app, I was able to create some "flavors" with an Ant script. The aim of this script was to do a copy of the Eclipse project with a different package name and with different resources (drawable, etc.)
I have migrated the project to Android Studio, deleted the Ant script and created some flavors.
But now, I have some issues to deserialize - in the new version of the app - an object serialized in the old version of the app.
Here a part of the stackstrace : Caused by: java.lang.ClassNotFoundException: com.company.app.flavor.bo.Player
In the old version, each flavors had it own package name :
com.company.app
com.company.app.flavor
In this new version, the code structure is com.company.app.flavor and I play with Gradle in order to generate the good applicationId for the flavor.
So, the applicationId for the flavor is correct, but the package name of the class seems to respect the project structure so, I cannot deserialize the original object with the package com.company.app.flavor.bo.Player into the object com.company.app.bo.Player.
If I change the structure of the project with com.company.app.flavor it will work for the flavor but not for the original one with the applicationId com.company.app.
So, is there a way, with Gradle or maybe another tool (proguard ?) to change the applicationId AND the package name for a flavor ?
Thank you in advance for your help.
Yes you can have ProductFlavor in gradle and this supposed to change the package name of the app. If you didn't hardcoded the classpath then serialization also should work without any issues.
android {
.
.
.
defaultConfig {
applicationId "lib4.com.stackoverflow"
}
productFlavors {
staging {
applicationIdSuffix ".staging"
}
preProduction {
applicationIdSuffix ".preProduction"
}
}
}
Once the apk got created, you can verify whether the package name has been changed or not by dragging and dropping apk on android studio and open Android Manifest. You will see the updated package name in the manifest in apk. But in source code, you will still see the package you provided earlier.

Importing Telegram API from GitHub repository to Android Studio

As you know Telegram API is open on GitHub. I tried to import it on my Android Studio. My android studio is up to date and also SDK is updated till the date. I have generated signed APK and tried to run project and got following errors. I have chosen x86 based to compile and tried to run it.
Screenshot.
http://img.prntscr.com/img?url=http://i.imgur.com/b0HqgmO.png
05/23 21:39:23: Launching TMessagesProj
The currently selected variant "arm-debug" uses split APKs, but none of the 1 split apks are compatible with the current device with density "560" and ABIs "x86".
Error while Installing APK
Any help would be appreciated.
Thank You!
The following image describes the solution.
in the defaultConfig (gradle Build file) add this at the end of android {} check for your architectures
android {
...
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk true
}
}
}

ndk.dir error in Android Studio

I was trying to use opencv library, so I imported one of its projects in Android Studio and when I tried to run it I got this error:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
NDK not configured.
Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties.
(On Windows, make sure you escape backslashes, e.g. C:\ndk rather than C:\ndk)
So I downloaded the ndk and I addes this line to the local.properties file where it became:
sdk.dir=C\:\\Users\\skoon\\AppData\\Local\\Android\\sdk
ndk.dir=C\:\\Users\\skoon\\AppData\\Roaming\\IDM\\android-ndk-r10d
but I still got this error which I didn't understand:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\skoon\AppData\Roaming\IDM\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-14 NDK_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\lib APP_ABI=all
Error Code:
2
Output:
make.exe: *** No rule to make target 'C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni', needed by `C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.o'. Stop.
I didn't change anything in the code, so what should I do? do I need to change or add any variables to point to the ndk?
P.S. This is my first time trying to build Android application so I don't have any experience.
Thank you in advance.
UPDATE:
To import the project I just used import project from file, then I synced the gardle, and run the project.
the package that I downloaded from opencv was the Android one, and I tried to use the face detection sample.
when I run it I got the error above.
You need to setup OpenCV librairies for your project. You can follow the instruction here.
OpenCV sample projects haven't support gradle officially. I think it will be easier if you start a new project and configure it to work as in examples.
I have implemented a tutorial project using Android Studio + NDK + OpenCV. You may have a look. https://github.com/quanhua92/NDK_OpenCV_AndroidStudio
Install NDK in your SDK manager, if you already installed open app's "build.gradle" replace these lines
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/', 'src/main/jni/'] } }
to
sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs' // mention your JNI lib path(where ".so" files contains)
jni.srcDirs = [] //disable automatic ndk-build call
}
I'm tried to configure OpenCV and its fixed

Categories