How to install 3rd party dependencies (like Alamofire) in a playground - swift-playground

I am new to Swift, Playground and Xcode. I am starting my first project and if everything is ok on the Xcode part, I am having difficulties importing 3rd party dependencies in playground. I have been googling for the last few days but unable to find a solution on how to install/import a pod in a playground. I would appreciate if someone can tell me how to do that or direct me to the right tool, doc set that explains it.

You should create an Xcode project, install there all the dependencies you need and then add playground file(New file-> Playground). You will be able to import 3rd party stuff.

You can create a playground with any number of 3rd party libraries with Arena:
arena https://github.com/finestructure/Gala
🔧 resolving package dependencies
📔 libraries found: Gala
✅ created project in folder 'SPM-Playground'

Related

Does 3rd party go library need to be recompiled when I use them?

I am a starter to use go. I found people publish go library just by pushing to github repo with a tag. It doesn't really compile anything when publishing. There is not any build artefact except source code.
When I use a 3rd party library, a command go get xxx is called to run. Will the library be compiled in my local along with my source code together? So go doesn't have any compiled library?
Does 3rd party go library need to be recompiled when I use them?
Yes.
Will the library be compiled in my local along with my source code together?
Yes.
So go doesn't have any compiled library?
Basically no.

Importing KMM library in multiple iOS modules via Cocoapods results in "... implemented in both ..."

I have been maintaining a shared library built with Kotlin Multiplatform for our Android and iOS native apps for quite some time now. Was working great until I decided to split the iOS app into multiple modules (frameworks). For starters I have one iOS app project and two dynamic frameworks, which are used by the app project. All 3 projects are using Cocoapods for 3rd party dependency management. Own modules are imported via framework embedding. No Cocoapods for the own modules needed, because we don't plan to make them available to other projects.
So the issue I am facing now is that whenever I import the KMM framework into more than one of the modules via Cocoapods, the build succeeds, but I receive errors at runtime like
Class MyClassInKMMProject is implemented in both
/Users/{user}/Library/Developer/Xcode/DerivedData/MyApp-hcbcxlfmsfiiqaccahedgcclxmiq/Build/Products/Debug-iphonesimulator/Common.framework/Common
(0x1189318d0) and
/Users/{user}/Library/Developer/Xcode/DerivedData/MyApp-hcbcxlfmsfiiqaccahedgcclxmiq/Build/Products/Debug-iphonesimulator/Core.framework/Core
(0x112a77ea8). One of the two will be used. Which one is undefined.
Since I need the shared KMM library basically in every module, I am stuck right now with this issue.
In some community I remember that someone mentioned static libraries can be imported only once when using multiple modules. But as far as I understand KMM generated frameworks and not static libraries.
I also tried using XCFrameworks instead of Frameworks, but it didn't change anything.
Anyone here knows how I can fix this?
Tried to find a solution for several days, but just found it after writing this question.
Adding isStatic=false to Gradle was the solution, which I got from this post: https://stackoverflow.com/a/65420364/390542

Google Play Billing Library missing

I'm trying to implement an in-app purchase in one of my apps. I'm running Android Studio 3.0.1 and i think everything is up to date. but when i go to the sdk manager (Tools->Android->Sdk Manager) the Google Play Billing Library is missing. I've tried updating everything i can think off. i download goolges test application and it seemed fine. following these instructions android billing my app will no longer comile. is this needed? can i install it another way? any ideas?
Just add the following dependency in the build.gradle file
implementation 'com.android.billingclient:billing:1.1'
As per the instructions here have you added the gradle dependency?
Add the following line to the dependencies section of the build.gradle file for your app:
dependencies {
...
compile 'com.android.billingclient:billing:1.0'
}

Best way to incorporate Volley (or other library) into Android Studio project

I've seen different advice on the best way to do this This question covers creating a jar. Elsewhere, I've seen advice to simply copy the volley source into your own project. This section on libraries at android.com would seem the most authoritative. However, after compiling volley, I don't have an aal library, whereas that section says I should have.
So my question is this: I have an existing Android Studio project with a standard layout, and a git repository; what should I do to add volley? Where should I download it to? How should I add it to Android Studio? Which Gradle files, if any, do I need to modify.
Hopefully, for those of you have done this a few times, this should be bread-and-butter stuff, but I haven't been able to find a straightforward description.
--
Updating, per Scott Barta's suggestion.
The gradle.build file in the volley repository has this line.
apply plugin: 'android-library'
According to the documentation: "Library projects do not generate an APK, they generate a .aar package (which stands for Android archive)." However, when I build the volley project, no .aar is created.
My feeling is that as Volley is a library project, created by the Android team, it is most probably intended to be generated and used as .aar package. Any advice on whether it would be preferable to generate a .aar, and how to do that, would be appreciated.
As pointed out by others as well, Volley is officially available on Github:
Add this line to your gradle dependencies for volley:
compile 'com.android.volley:volley:1.0.0'
To install volley from source read below:
I like to keep the official volley repository in my app. That way I get it from the official source and can get updates without depending on anyone else and mitigating concerns expressed by other people.
Added volley as a submodule alongside app.
git submodule add -b master https://github.com/google/volley.git volley
In my settings.gradle, added the following line to add volley as a module.
include ':volley'
In my app/build.gradle, I added a compile dependency for the volley project
compile project(':volley')
That's all! Volley can now be used in my project.
Everytime I want to sync the volley module with Google's repo, i run this.
git submodule foreach git pull
LATEST UPDATE:
Use the official version from jCenter instead.
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
The dependencies below points to deprecated volley that is no longer maintained.
ORIGINAL ANSWER
You can use this in dependency section of your build.gradle file to use volley
dependencies {
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
}
UPDATED:
Its not official but a mirror copy of official Volley. It is regularly synced and updated with official Volley Repository so you can go ahead to use it without any worry.
https://github.com/mcxiaoke/android-volley
Nowadays
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
A lot of different ways to do it back in the day (original answer)
Add volley.jar as library
Download it from: http://api.androidhive.info/volley/volley.jar
Place it in your [MyProjectPath]/app/libs/ folder
Use the source files from git (a rather manual/general way described here)
Download / install the git client (if you don't have it on your system yet): http://git-scm.com/downloads
(or via git clone https://github.com/git/git ... sry bad one, but couldn't resist ^^)
Execute git clone https://android.googlesource.com/platform/frameworks/volley
Copy the com folder from within [path_where_you_typed_git_clone]/volley/src to your projects app/src/main/java folder (Integrate it instead, if you already have a com folder there!! ;-))
The files show up immediately in Android Studio. For Eclipse you will have to right-click on the src folder and press refresh (or F5) first.
Use gradle via the "unofficial" maven mirror
In your project's src/build.gradle file add following volley dependency:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// ...
compile 'com.mcxiaoke.volley:library:1.+'
}
Click on Try Again which should right away appear on the top of the file, or just Build it if not
The main "advantage" here is, that this will keep the version up to date for you, whereas in the other two cases you would have to manually update volley.
On the "downside" it is not officially from google, but a third party weekly mirror.
But both of these points, are really relative to what you would need/want.
Also if you don't want updates, just put the desired version there instead e.g. compile 'com.mcxiaoke.volley:library:1.0.7'.
As of today, there is an official Android-hosted copy of Volley available on JCenter:
compile 'com.android.volley:volley:1.0.0'
This was compiled from the AOSP volley source code.
UPDATE:
compile 'com.android.volley:volley:1.0.0'
OLD ANSWER:
You need the next in your build.gradle of your app module:
dependencies {
compile 'com.mcxiaoke.volley:library:1.0.19'
(Rest of your dependencies)
}
This is not the official repo but is a highly trusted one.
For incorporate volley in android studio,
paste the following command in terminal ( git clone https://android.googlesource.com/platform/frameworks/volley ) and run it. Refer android developer tutorial for this.
It will create a folder name volley in the src directory.
Then go to android studio and right click on the project.
choose New -> Module from the list.
Then click on import existing Project from the below list.
you will see a text input area namely source directory, browse the folder you downloaded (volley) and then click on finish.
you will see a folder volley in your project view.
the switch to android view and open the build:gradle(Module:app) file and append the following line in the dependency area:
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
Now synchronise your project and also build your project.
I have set up Volley as a separate Project. That way its not tied to any project and exist independently.
I also have a Nexus server (Internal repo) setup so I can access volley as
compile 'com.mycompany.volley:volley:1.0.4' in any project I need.
Any time I update Volley project, I just need to change the version number in other projects.
I feel very comfortable with this approach.
add
compile 'com.mcxiaoke.volley:library:1.0.19'
compile project('volley')
in the dependencies, under build.gradle file of your app
DO NOT DISTURB THE build.gradle FILE OF YOUR LIBRARY. IT'S YOUR APP'S GRADLE FILE ONLY YOU NEED TO ALTER
This solution is for Kotlin DSL (build.gradle.kts):
dependencies {
implementation("com.android.volley:volley:1.2.1")
// ...
}

Xcode, update project file automatically

I have many projects that use a bunch of exact same class.
Is there a way to add a script to Xcode, so, each time i compile, he go to a network folder and update is files from there... If newer. (i do this step manually, but could be great to automate it)
Thanks
You could add a "run script" build phase to copy over files before compiling if that's really what you want to do. That would catch updates for you but I don't think it would help you if new files are added (though copying them into a location your project has a folder reference rather than a group pointing to might work).
That said I think there's a better solution. It sounds like you're reinventing a process for managing project dependencies when you could use existing tools. I would publish those shared classes as a library and add it to each project using CocoaPods and a reference to the library's git repository. That way you just need to run a pod install to get the latest version of your library. A good dependency manager gives you a clear understanding of which version of your dependencies you're currently using, control over when to update them, handles installing dependencies of your dependencies, and will avoid link errors from multiple static libraries attempting to each include a copy of the same common dependency.

Resources