I have separate repositories for Android and iOS, ...
# touchlab-tools
a
I have separate repositories for Android and iOS, and I’ve created a new repository for sharing KMM code, which is linked to the Android codebase via submodules. This KMM repository only contains the modules (e.g.,
shared
,
:shared:featureA
,
:shared:featureB
, etc.) and does not include a
settings.gradle
or
gradle.properties
file. I want to publish the KMM code as an SPM package for iOS, but I don’t want to publish any AAR files since Android developers are already using the KMM module directly as a regular module. My goal is to ensure that all tags and packages, including the
Package.swift
file, are managed within the KMM repository. Can anyone recommend resources or guidance on setting up KMMBridge for this scenario?
b
Are you using Touchlab's Default Github Workflow to do the publishing?
I think by default it only publishes the ios binaries.
k
KMMBridge only publishes Android is you want that. You can publish iOS only.
There's a new version which I haven't quite "released" yet. Docs here: https://touchlab.co/kmmbridge/. Can be used as
1.0.0-alpha1
. Template here: https://github.com/touchlab/KMMBridgeSPMQuickStart. The new KMMBridge version is very focused on SPM and removes a lot of the dev versioning complexity of previous versions. It also lets you add the binary XCFramework zip as a release artifact rather than using GitHub Packages.
However, depending on goals, I'd continue using source. Not sure what those goals are, though: https://touchlab.co/kmp-teams-use-source
a
Thank you for sharing the resource. I tried using this version of KMMBridge, and the GitHub action completed successfully, creating a new release with the ZIP file, the XCFramework, and a tag. However, it didn't generate a Package.swift file . How should I consume this in my iOS app? Am I missing something? From what I understand, earlier versions of KMMBridge, like 0.5.x, also created a Package.swift file.
k
It creates it in the tag
There's a commit with the Package.swift file. You'll need to have one in the root already. The idea is the main branch is where you might be doing dev, so you put a Package.swfit there that points to a local build. When KMMBridge runs, it generates a Package.swift pointing at your published XCFramework. That only exists in the tag commit.
thank you color 1
a
seems like the release contain Package.swift file, but the issue here is that when I add it in xcode it says invalid archive returned , on seeing the package.swift file the remote url seems not not pointing to the xcframework zip file it's something like https://api.github.com/repos/something/kmm-modules/releases/assets/187382474.zip but this 187382474.zip doesn't exist . the framework zip is instead something like shared.xcframework.zip. Am I missing something here ?
You didn't configure netrc, or did not do so correctly.
a
Yes, I have done added this.
k
Try to download the url in your browser
a
404, seems like something is wrong with the netrc ?
but I have also added this in my keychain
k
In your browser, try to download the zip file with the weird URL
A browser that is logged into github
Actually, never mind. that won't work
a
No, its not working too
k
Anyway, if you get a 404 from Xcode, then you probably haven't configured netrc correctly.
That url is the direct url for the file. I don't know why github does it that way
a
when I try from browser in which my github account is already logged in I get this error
Copy code
{
  "message": "Not Found",
  "documentation_url": "<https://docs.github.com/rest/releases/assets#get-a-release-asset>",
  "status": "404"
}
k
If you open the GitHub release in your browser, can you download the zip file from there?
a
yes from there I am able to download but not from the remoteURL that the Package.swift is pointing to
k
I'd bump the version and try running it again. It's hard to debug more without seeing the build info and config. I don't know how you'd get an incorrect file url
a
not sure what I am doing wrong, I cloned the KMMBridgeSPM templet and tried to run the github action , but the url that I am getting still not working returning 404. I also the the netrc file is configured correctly as running
curl -n <https://api.github.com/user>
from my terminal returns a valid response
k
Hmm. You can manually check that the url matches with the GitHub cli tool https://cli.github.com/
gh release list
to get the release, then
gh release view
to see the assets. I think that'll show the "real" url of the file. Long story, but you need it.
If they match, then I'm confused. If they don't, something really weird is wrong.
Out of curiosity, I assume this is a private GitHub repo. Is it enterprise GitHub?
a
I have both actually and for both it's not working. What is more weird is that when I try to run curl -n {url} in my terminal, I get the information about the exact shared.xcframework,zip that it's pointing to but opening the url or adding it to xcode just return 404
k
OK, if you get the info in your browser, it's your Xcode config. GitHub returns 404 when you don't have access, which makes sense (<-- Sarcasm. That doesn't make sense at all)
If you're using netrc and keychain, I don't know how that works or which will be used by Xcode.
a
Something like this : -
Copy code
test@Abhs-MacBook-Pro ~ % curl -n <https://api.github.com/repos/programmer/SPMKMM/releases/assets/187399888.zip>
{
 "url": "<https://api.github.com/repos/programmer/SPMKMM/releases/assets/187399888>",
 "id": 187399888,
 "node_id": "RA_kwDOMmS-vM4LK37Q",
 "name": "allshared.xcframework.zip",
 "label": "",
 "uploader": {
  "login": "github-actions[bot]",
k
Yeah, if that url matches, then curl is OK. Xcode is still not working.
a
but both keychain and netrc file uses the same PAT
k
Can you send the netrc (without the PAT, obviously).
a
sure
k
You can remove the username too if needed
a
Copy code
machine <http://api.github.com|api.github.com>
 login programmer
 password ghp_YP4WtzH2FDJFJDJFJ09LFb9
have changed the PAT 🙂
k
OK 🙂 Was just going to say, disable that ASAP
😅 1
a
this is correctly configured right? or there is something missing ?
k
Well, either: • Xcode ignores netrc and uses the keychain, which isn't setup correctly • Your PAT doesn't have the permissions necessary to download the file
The netrc looks fine
a
I know this may sound horrible, but to just test I have literally given all the permission available out there just to ensure it's not a permission issue
trying to del the keychain entry and try again
k
Not horrible for testing
This whole process is a pain, though. Wish I had extra free time. I'd write some kind of "check your config" cli command.
a
still not found 🥲
This whole process is a pain, though. Wish I had extra free time. I'd write some kind of "check your config" cli command.
That would be really helpful!.
k
Well, hmm. If the PAT has all permissions, and netrc is set up, and the keychain entry has been removed, I'm a bit stuck. Screenshot of the Xcode error? Also, when adding in Xcode, what version are you adding? You can add by branch, but main won't have the right url. I don't think this is the issue, but something to check.
a
There is nothing in the xcode error it just says invalid archive returned from {url} which is requried by binary target shared.. . Also while trying to download it through my browser it just return 404
k
OK. I'd suggest dropping the SPM (if you added anyway, overriding the error message). Then re add it. Take a screenshot of the SPM config screen, then a screenshot of the Xcode error.
a
could you please explain a bit , I didn't got
SPM config screen
Are you talking about this ?
Screenshot 2024-08-21 at 8.53.27 PM.png,Screenshot 2024-08-21 at 8.53.53 PM.png
k
could you please explain a bit , I didn't got
SPM config screen
Are you talking about this ?
The screenshots you sent are what I was talking about.
I was looking for that, which looks correct.
You can try this (the error says the config is cached). Otherwise, I don't know.
I assume this isn't public, again, but if there's nothing sensitive in the repo and you're comfortable with it, invite me to the repo and I'll try from here.
a
I've noticed something in the
Package.swift
file that I'm hoping you can clarify. The URL for the GitHub release asset is structured like this:
Copy code
<https://api.github.com/repos/owner/repo/releases/assets/asset_id.zip>
However, I've found that this URL doesn't actually allow direct downloading of the asset. When I use curl to access the API endpoint
Copy code
curl -n <https://api.github.com/repos/owner/repo/releases/assets/asset_id>
It returns a JSON response containing a
browser_download_url
, which seems to be the actual URL for downloading the asset as I can download the zip from my browser (in which I have already logged in ) This raises a few questions: 1. Is the current URL in
Package.swift
correct? It seems like Xcode wouldn't be able to download the asset using this URL. 2. Shouldn'twe be using the
browser_download_url
instead? I noticed that previous versions of KMMBridge used a downloadable URL directly. https://github.com/touchlab/KMMBridgeSKIETemplate/blob/7f16a56c98c5f2f3989233c78b6beb784771cf07/Package.swift
> invite me to the repo and I'll try from here. Sure sending you the invitation. Could you please help me with your github username
k
Hmm. It has been working, but I'll take a look at what you sent. It'll be a while. I'm already way overdue for the other things I'm doing today (I have multiple slack threads going on right now for different things :))
Sure sending you the invitation. Could you please help me with your github username
kpgalligan
a
have sent you the invitation.
Since this is kind of blocker for me to proceed for KMM in my team? Will it be a good idea to use KMMBridge 0.5.X for just spm as I thing this should work as it uses download url
k
Let me look quick at your repo and try importing to Xcode, but perhaps.
🆗 1
Sort-of good news. Works for me 🙂
Screenshot 2024-08-21 at 12.03.43 PM.png,Screenshot 2024-08-21 at 12.07.24 PM.png
It still has to be an access issue. I had no trouble.
a
🫠what am I doing wrong here!.!!
k
double-check the keychain (that it's removed). Double check the netrc, or maybe drop it and recreate it. Make sure the PAT is the "all access" one. Restart Xcode. You might need to restart the keychain. Unlikely, and I wouldn't know how (other than a reboot).
This whole process sucks, though. You're not the first to have this kind of issue. There are many moving parts that can fail, and the error messages aren't helpful.
a
ok let me just do the whole thing. again
This whole process sucks, though. You're not the first to have this kind of issue. There are many moving parts that can fail, and the error messages aren't helpful.
is it stable enough to use in prod as I am planing to do so ?
k
Yeah. Mine works, but of course, I've been doing this for a few years. Muscle memory on the setup.
is it stable enough to use in prod as I am planing to do so ?
Yeah, it's fine. The config sucks. Prod is super stable. Ironically, it's SPM, Xcode, and GitHub being extra careful, but not extra helpful. Once it's set up, you'll forget about it. My config works because it was set up a while ago, so I just needed to be invited to your repo. Assuming other devs will use this, make sure you very clearly document the setup.
Also, this is another reason I suggest building from source instead. Binaries are "easy", unless you run into this stuff. Source has an initially longer build, but Gradle caches the build, so it's a tradeoff, but you'd also avoid all of this mess. https://touchlab.co/kmp-teams-use-source
a
I actually wanted to share the source, I have gone through your multiple blogs regarding library mode and the bidirectional mode . But the issue for me is the I have added KMP repo as a submodule to my android repo so they have the source but for ios , I dont know how should I approach this like (currently not using gitportal or something like that) how wold I build the kmm libraries locally and will connect to ios app , how my xcode cloud will build the ios app in this case like mostly the linking part. Currently I was thinking of publishing a spm library in my KMM repo so that It can be consumed directly in my ios app.
Yeah, it's fine. The config sucks. Prod is super stable. Ironically, it's SPM
Tried recreating the netrc file but it's still not working for me!.
k
Have anybody else that could try? Could be some kind of access block, although I can't imagine what.
a
I will be sharing link to my teammates to verify if they are able to pull the spm library
Also are you able to download the zip file using that url in your browser or it's throwing 404 ?
k
404 in the browser.
That's not exactly what I expected, but debugging this is difficult because GitHub often does "unexpected" things. I would like to check what I get in the browser from other KMMBridge-generated urls.
I get info back if I try a KMMBridge release on a public repo, but I get 404 if I try a KMMBridge release on a private repo (I'm talking about my repos). GitHub is weird.
I just added my private repo, which is also using the KMMBridgeQuickStart template, and it works. So, private repos return 404 in the browser for that url, but it works in Xcode.
All of this would be easier with some kind of "Package hosting", but that would need to be a paid service, and for this use case specifically, I can't imagine setting that up would be worth it. GitHub prevents you from downloading binaries from public repos without auth because then people would use it for free hosting and run up traffic costs.
S3 would be good/cheap, but they don't support basic auth, so you'd need to write a service in front of it.
a
is there anything apart from this in netrc file ? machine api.github.com login programmer password PAT
k
Copy code
machine <http://api.github.com|api.github.com>
  login kpgalligan
  password ---
That is the entirety of mine.
a
I tried adding https://github.com/touchlab/KMMBridgeSPMQuickStart and its working fine. But AFAIK, github uses authentication for public repo too ?
k
But AFAIK, github uses authentication for public repo too ?
It does.
a
ahh! finally working I am still not sure how !!
k
Dumb question, but is the account for your PAT and the account you generally use GitHub with the same? As in, do you have private and work accounts?
a
same account
1
k
Forget the last question. Maybe it was a cache thing?
a
I guess so
k
Well, anyway. Glad it's working. Make sure you have good setup docs for others 🙂
a
sure 🙂, the one that I have shared with you is still not working for that project (and i think it still a cache issue )
k
don't forget to revoke my access 🙂
a
yes sure
Thanks for the help 🙂
👍 1
I am actually now facing a weird issue not sure what causing it as earlier it was working fine. When I run iosPublish action it actually creates a tab and upload all the files like xcframewrok.zip and all but the issue it the commit in the release actually points to my latest commit (which In my case is adding readme) and does not contain Package.swift (which earlier was working). I tried re-running the action again but still it points to my latest commit
k
Hmm. That is odd.
Ah, that's in the "real" repo, not the test one.
Looking at the zip size, I assume you've got a bunch of code already in there, which means you're integrating this into an existing repo. What does the GitHub workflow script look like?
a
it's actually same as the template that you have provided for SPM, I am having a separate repo for KMM (same as the template) in which I was running the iosPublish action. but after a certain commit which just include some code changes, gradle version change in gradle -wrapper and a file in .build/workspace-state.json(since till then it was not added in gitignore) , it stopped working , thogh the action was getting completed every single time but Package.swift was not there in the commit section
k
OK. Any other info would help. Hard without the build log, etc.
a
is this has to do anything with the .build or .kotlin ? I noticed deleting these files and adding it to gitignore causing the issue ? Am just not 100% sure but
Screenshot 2024-08-22 at 9.03.46 PM.png
k
I mean the GitHub actions build log. Maybe the build is failing, but our publish script is not cleaning up properly.
a
logs_27482339826.zip
k
Hmm. Try
0.0.2
. This new flow has to do something "weird" to get artifacts into GitHub releases. It creates the release, uploads the file, then updates the tag for that release. I'm not sure what's going on with this one, but I'm curious if a completely new release would work. I'm thinking maybe there's something going on with a "first one" in your repo for some reason. (The logs look fine. Nothing failed)
a
by 0.0.2 , you are talking about the spm version right ? if yes , have tried that also but that didn't worked too
Also when I am reverting back to my previous commit , it just works fine
k
In the shared repo, bump the version to 0.0.2, then run the publish workflow again (to be clear). Same result?
a
yes
k
Also when I am reverting back to my previous commit , it just works fine
You're reverting
main
in the KMP repo back to the prior commit (force-push or applying the changes in reverse?), and that "works". Define "works". I feel like
0.0.1
was the first release, and that wasn't working.
a
so I was just testing out various things , so for a particular commit, I started the workflow and 0.0.1 was published with the package.swift in it then after certain change , I started the workflow again (have deleted the previous tag and the release from the repo), this time the release and the tag is generated but the package.swift file is missing . When I revert my commit and try to start the workflow again it just work