I am working on a Flutter app inside of the latest stable version of Android Studio. I need to use a native SDK in this project since that vendor does not yet support Flutter. The example I am working off of was using the old support libraries and that was causing trouble so I am migrating things to androidx. I notice though that as I attempt to fix the errors in an Activity, like Unresolved reference: AppCompatActivity for example, that Android Studio does not recognize the Activity as a Kotlin file. In other words, none of the hints that show up work and in fact, no typo is ever shown as a syntax error. It's treating the Activity like a plain text file! You can type anything you want (like this_is_clearly_a_syntax_error as a line by itself) and no highlighting of an error will occur.
How do you get the Kotlin files to be treated like they do in a normal Android app?
Looks like you have to go in an physically mark the android directory as Source. So, go to File->Project Structure then select Module on the left. Left click on Android, then select Source then hit Apply.
Related
I have a problem and I would like your help :)
I received a native Java project from Android Studio and I want to know how I can configure my environment, the first time I tried I had a lot of errors with gradel.
Is there a way to know exactly what settings are needed to start project maintenance?
As long as you have installed Android Studio and are able to create sample projects, you should be set up.
Gradle should show you all the problems which your legacy project has. I assume, that you will see a lot of warnings which can be ignored at first.
You might have problems with a missing key.properties file.
Some dependencies might not be available anymore.
You have to resolve all the issues manually. There aren't any special settings.
I am following the hands on tutorial on KMM, and reached the point where I should write the iOS part of the app, however, when I head over to any of the .swift files, there's no syntax highlighting, the content appears as a plain text file.
Android Studio: 4.1.1 (latest at the moment of writing)
KMM Plugin: 0.2.0-release-65-Studio4.1 (latest at the moment of writing)
From what I see, the iosApp is not recognized at all as a module (like the androidApp, that has the name of the module highlighted via bold font), I suppose that is the issue.
Any thoughts on how to fix this?
You'll need to use Xcode or (possibly) AppCode. Android Studio and the KMM plugin do not understand or highlight Swift code directly.
If anyone runs into the same issue with AppCode not highlighting Swift, I just had to close the project and reopen it.
I'm getting red letters in my AndroidManifest.xml and don't understand what they mean. At the moment everything seems to be working as should. But will I get any problems down the road?
Nope, Android Studio can't understand the Android content when a Flutter project is opened.
It can either understand the Flutter directory structure when Flutter is opened. This is what enables Code Completion and other nice features when making Flutter apps.
If it's a simple Android project, then it can easily understand the Gradle files and your Java/Kotlin.
What this means for you as a Flutter developer is that, when you are editing native Android or iOS code. You will not get code completion. Android Studio will not be able to tell you about the errors in your code.
The Flutter team is working on this. So that you can have all the cool IntelliJ features for editing Native code EVEN when you have a Flutter project is opened.
Also, I think if you open the android separately, then you should be able to see properly. (Maybe, I'm not sure).
You can now open the Android part of your Flutter project by right clicking on the project name in the project window, choose Flutter and then Open Android module in Android Studio.
The opened Android project will have code completion and all the red letters will most likely turn other colors :)
The environment...
I have a brand new Visual Studio 2015 Android NDK Solution.
This contains 2 projects (the default template code that is generated by visual studio):
A native activity. This is where I want to put Android specific code. It has some default code which fades the screen colour between green and black.
A 'Packaging' project to help with deployment.
I have deployed this successfully to an Intel HAXM virtual device as well as to a real device connected via USB. All good so far.
I then added an Android dynamic library project (.so) - this is where I want to put core code (platform agnostic).
I added a reference to this Core library from the native activity project.
Everything compiles and links fine. I can still create an .APK file.
Other info:
Android SDK 5.1 (Android-22)
Android NDK 21
x86
Clang 3.8
C++ 11
Not using Make files or Gradle
The problem...
Now whenever I deploy to the virtual/real device I get the following error (taken from logcat)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.NATester/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.NATester-2/lib/x86/libNATester.so
Things I have tried...
changing the Core library to static (.a)
checked the android device to see if the file exists - it does exist.
Manually deploying the .APK to the android device.
Some articles have suggested using Java code to load the libraries - I want to avoid calling Java code e.g. System.LoadLibrary as this seems like a hack - I feel that it should be possible to to have a pure C++ application on android. I can't be the only person to run into this issue?!
This looks relevant but old and again an unnecessary hack for what must be very common situation
- Can't load native shared library with dependencies in a native activity app
- https://github.com/ikonst/android-dl
For what its worth, I am a seasoned C# developer with Visual Studio (15 years).
I therefore take a lot of things for granted when developing apps - this is my first project using C++/Android and it seems more of a manual battle to get everything to work!
Been struggling for a while but managed to deploy the libraries, quite easy in the end.
Right click on the project [theProject (Andorid-xx)] in the Solution Explorer and select add new item, add your .so library.
Right click on the newly added library and select properties, item type should be library, set Content to Yes, this will deploy the lib.
as the following picture shows, the source of ListView is not included by the sdk, so how to get the source for this class?
then i may debug into the code of Listview.
Edit1: i am using sdk 2.2, it don't have a module named source code, only android 4.x have such module:(
Type android into your console to open the Android SDK Manager. Expand the Android version you would like to use, mark the Sources for Android SDK checkbox and hit Install. That's everything, you need to do. You will find the sources afterwards in <SDK_PATH>/sources/android-XX. You IDE should now be able to debug into the code (at least NetBeans does).
Edit (for 2.2)
I guess if you really want the sources for 2.2, you will need to checkout the whole android project and switch to the required tag. (Get a list of all tags with git tag -l) You could copy that code to the above mentioned folder, and see if your IDE detects it there.