11# Libres
22
3- Resources generation in Kotlin Multiplatform.
3+ String resources generation in Kotlin Multiplatform.
4+
5+ > [ !IMPORTANT]
6+ > Starting from __ version 2.0.0__ , this plugin __ no longer supports image sharing__ .
7+ > If you want to continue using it for strings, you’ll need to migrate your image sharing to another solution —
8+ > for example, [ Compose Multiplatform Resources] ( https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-multiplatform-resources.html ) .
9+ >
10+ > __ Why?__
11+ > I like my implementation for strings — having direct access to ` String ` is much more convenient than various wrappers in alternative solutions.
12+ > However, I’m not happy with my implementation for images: it turned out to be unintuitive, dependent on the CocoaPods plugin on iOS, and rather unstable.
13+ > I don’t have the time or motivation to maintain and improve this functionality, so I decided to remove it.
414
515## Setup
616
@@ -9,7 +19,7 @@ Resources generation in Kotlin Multiplatform.
919
1020buildscript {
1121 dependencies {
12- classpath(" io.github.skeptick.libres:gradle-plugin:1.2.4 " )
22+ classpath(" io.github.skeptick.libres:gradle-plugin:2.0.0-alpha01 " )
1323 }
1424}
1525```
@@ -29,63 +39,13 @@ libres {
2939}
3040```
3141
32- ## Jetpack Compose
33-
34- ``` kotlin
35- // build.gradle.kts (module)
36-
37- kotlin {
38- commonMain {
39- dependencies {
40- implementation(" io.github.skeptick.libres:libres-compose:1.2.4" )
41- }
42- }
43- }
44- ```
45-
46- This artifact provides ` painterResource ` function that can be used
47- to get ` Painter ` from ` io.github.skeptick.libres.Image ` in common code.
48-
4942## Supported platforms
5043
5144- ** Android** , ** JVM** , ** iOS** , ** MacOS** and ** JS** in Kotlin Multiplatform projects.
5245- Pure Android or JVM projects with Kotlin.
5346
54- ## Requirements
55-
56- | | |
57- | -----------------------| -------------------------------|
58- | Kotlin | 1.6.20+ |
59- | Android | 4.1+ (API level 16) |
60- | Android Gradle Plugin | 7.0+ |
61- | iOS | 13+ (when using vector icons) |
62-
63- \
64- :bangbang : Also you need to use [ CocoaPods] ( https://cocoapods.org/ ) and
65- [ CocoaPods Gradle plugin] ( https://kotlinlang.org/docs/native-cocoapods-dsl-reference.html )
66- to export images to iOS application.
67- If you aren't reusing images in iOS then this condition is optional.
68-
6947## Known issues
7048
71- ### iOS
72- :warning : Cocoapods caches list of resource directories when ` pod install ` is called,
73- so bundles directory must exist at this time.
74- You won't see this issue if your ` .podspec ` is in ` .gitignore `
75- in any case it's best to be safe with this hook in your Podfile.
76-
77- Suppose your Kotlin Framework is added like this:
78- ``` ruby
79- pod ' umbrella' , :path => ' ../common/umbrella/umbrella.podspec'
80- ```
81-
82- Then this hook will look like this:
83- ``` ruby
84- pre_install do |installer |
85- FileUtils .mkdir_p(installer.sandbox.root.to_s + ' /../../common/umbrella/build/generated/libres/apple/libres-bundles' )
86- end
87- ```
88-
8949## Usage
9050
9151Resources must be stored in ` {yourSourceSetName}/libres `
@@ -95,9 +55,6 @@ Multiplatform:
9555├── commonMain
9656│ ├── kotlin
9757│ └── libres
98- │ ├── images
99- │ │ ├── vector_image.svg
100- │ │ └── raster_image.png
10158│ └── strings
10259│ ├── strings_en.xml
10360│ └── strings_ru.xml
@@ -108,9 +65,6 @@ Android or JVM:
10865├── main
10966│ ├── java
11067│ └── libres
111- │ ├── images
112- │ │ ├── vector_image.svg
113- │ │ └── raster_image.png
11468│ └── strings
11569│ ├── strings_en.xml
11670│ └── strings_ru.xml
@@ -151,71 +105,3 @@ MainRes.shared.string.simple_string
151105> This seems familiar but ability to work directly with strings instead of resource IDs can be misused.
152106***
153107#### [ More about localization] ( docs/LOCALIZATION.md )
154-
155- ### Images
156-
157- Supported formats:
158- - PNG
159- - JPG
160- - WEBP (Android 4.3+, iOS 14+)
161- - SVG (iOS 13+)
162-
163- For Android SVGs are converted to
164- [ vector drawable] ( https://developer.android.com/develop/ui/views/graphics/vector-drawable-resources ) ,
165- for other platforms they copied as is.
166-
167- #### Image modifiers
168- The image filename can contain modifiers in parentheses listed through underscores.
169-
170- > ** orig**
171- >
172- > Used for iOS. Marks image as ` Original ` (similar to ` Render As: Original Image ` in XCode Assets Manager).
173- Recommended for multicolor images.
174-
175- > ** size**
176- >
177- > Applies to bitmaps. Reduces image resolution to specified size.
178- > - For Android generate images from mdpi to xxxhdpi (where mdpi is 1:1 in pixels to specified size)
179- > - For iOS generate images from @1x to @3x (where @1x is 1:1 in pixels to specified size)
180- > - For JVM and JS a single image of specified size is generated.
181-
182- Filename examples:
183- ```
184- some_hd_image_(100).jpg
185- app_logo_(orig).svg
186- my_colorful_bitmap_(orig)_(150).png
187- ```
188- Kotlin:
189- ``` kotlin
190- MainRes .image.some_hd_image
191- MainRes .image.app_logo
192- MainRes .image.my_colorful_bitmap
193- ```
194- Swift:
195- ``` swift
196- MainRes.shared .image .some_hd_image
197- // or MainRes.shared.image.someHdImage if `camelCaseNamesForAppleFramework` enabled
198- ```
199-
200- <details >
201- <summary ><h3 >Why do I see a black/blue box instead of my picture?</h3 ></summary >
202-
203- I'm pretty sure your picture is multicolor JPG/SVG with opaque background.
204- This happens because UIKit recolors this image with accent color.
205-
206- Solution: add (orig) modifier to image filename, e.g.: ` my_image_(orig).png `
207- </details >
208-
209- <details >
210- <summary ><h3 >How to export bitmap from Figma?</h3 ></summary >
211-
212- To obtain bundle of PNG images with different resolutions (mdpi-xxxhdpi for Android and @1x- @3x for iOS) do following steps:
213- 1 . Export image from Figma with x4 scale (it matches to the biggest used size — xxxhdpi on Android)
214- 2 . Put it to ` libres/images ` package
215- 3 . Remember the biggest side value of image represented in Figma
216- 4 . Rename image with the value of the biggest side:
217- ** pic.png** -> ** pic_ (orig)_ ({side_value}).png** or ** pic_ ({side_value}).png**
218-
219- Sample:
220- Image size in Figma is ** 240x89** . Final image name is ** pic_ (orig)_ (240).png**
221- </details >
0 commit comments