Is there a possibility to target android with kotl...
# multiplatform
m
Is there a possibility to target android with kotlin, but having android sdk code accessible only from androidMain? Not from commonMain and others?
c
Android SDK can't be accessed from common code anyway
m
At least in Android Studio, it can. Of course once i build for different platform, it will fail, but this question is more about "why are imports not red"? "why can I build on android with android SDK inside commonMain"?
which means, that while we undergo refactor of our modules to be platform independent (for future use, now still only android), then we don't get discouraged from having android SDK code in commonMain package
c
There might be something wrong with your setup. Adding Android-only methods in commonMain shouldn't compile.
m
I tried it in many many example repositories and it is the same thing. Please, check out for example this repository: https://github.com/joreilly/PeopleInSpace and tell me what is wrong with their setup, that i can add DisplayMetrics from android.content package into commonMain part AND successfully build on android platform. It is bugging us for 3 days already and we cannot seem to solve it. As far as our understanding is, applying plugin
Copy code
com.android.library
makes all folders inside module able to access android sdk. However, without it, we cannot add
Copy code
android()
target into kotlin block.
j
reinstall AS, it is not normal
m
We did and it is happening on both Linux distribution and Windows. Could someone here try it please? Sometimes the studio has not automatically added imports, but manually pasted import was possible to build and reference through.
m
Forked linked project tried importing
DisplayMetrics
in common
PeopleInSpaceRepository.kt
file, but got error as expected. Tried that on mac, but other platforms should display same behaviour.
Oh, I get what you mean - manually adding the import doesn't display the error, but normally autocomplete wouldn't show it as an available import. So I guess your problem is that when copy/pasting from android into common the imports get resolved, correct?
m
@MJegorovas Yes exactly 🙂 While refactoring, we get rid of fragments, androidx etc., but activity, displayMetrics etc imports will not warn us.
m
Yeah, this is a bit problematic. The only thing I can think of is raising an issue in YouTrack
👍 1