Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify resource management for iOS #3340

Merged
merged 12 commits into from
Jul 18, 2023
Merged

Conversation

AlexeyTsvetkov
Copy link
Collaborator

@AlexeyTsvetkov AlexeyTsvetkov commented Jul 11, 2023

With this change:

  • Resources from src/<SOURCE_SET_INCLUDED_IN_IOS_COMPILATION>/resources are copied to the application bundle without any additional configuration;
  • Resource management is now compatible with regular frameworks (in other words Cocoapods are not required);
  • When Cocoapods are used, running podInstall after modifying resources is not required. It is still required to run podInstall once, check the instruction below for details.

Known limitation

⚠️ Copying resources is limited to one module, which produces an iOS framework! Publishing resources and copying resources from other modules will be supported in future versions.

Configuring Cocoapods

  1. Remove extraSpecAttributes["resources"] = ... from your Gradle build script:
kotlin {
    ios()
    iosSimulatorArm64()

    cocoapods {
        // ...
        extraSpecAttributes["resources"] = "['src/commonMain/resources/**', 'src/iosMain/resources/**']"
    }
}
  1. Run podInstall task once!

Configuring regular frameworks

If your XCode project already has a run phase ./gradlew :shared:embedAndSignAppleFrameworkForXcode, no additional configuration is required.

Converting Cocoapods configuration to regular framework

  1. Find the module, which contains Cocoapods configuration. In our pre-1.5 Compose Multiplatform templates and examples that usually was the :shared Gradle module.
  2. Run pod deintegrate <PATH_TO_XCODEPROJ_FILE> in the terminal:
cd shared/
pod deintegrate ../iosApp/iosApp.xcodeproj
  1. Copy framework configuration from cocoapods to the iOS targets configuration.
kotlin {
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries {
            framework {
                // Copy the content of `cocoapods.framework` here
            }
        }
    }

    cocoapods {
        framework {
            // Copy this to the ios targets configuration
        }
    }
}
  1. Remove cocoapods section, and the usage of org.jetbrains.kotlin.native.cocoapods plugin from plugins block.
  2. Open XCode project in XCode.
  3. Add a new run script build phase:
Screenshot 2023-07-27 at 14 37 30
  1. Run embedAndSign Gradle task in the new run phase:
cd "$SRCROOT/.."
./gradlew :shared:embedAndSignAppleFrameworkForXcode
  1. Move (simply drag&drop) the run phase to run before the compile sources phase.
Screenshot 2023-07-27 at 14 47 46
  1. Add the following snippet to the Other Linker flags under the Linking section:
$(inherited) -framework shared
Screenshot 2023-07-27 at 14 52 28
  1. Add the following snippet to the Framework Search Paths under the Search Paths section:
$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)
Screenshot 2023-07-27 at 15 03 21

Resolves:

Introduces new a new task 'sync<FRAMEWORK_CLASSIFIER>ComposeIosResources',
which collects resources from all source sets, included in iOS targets.

With this change:
* CocoaPods integration does not require any configuration or calling 'pod install' after changing resources.
    * Important: existing projects need to remove 'extraSpecAttributes["resources"] = ...' from build scripts, and rerun `./gradlew podInstall` once!
* Without CocoaPods, the resource directory should be added to XCode build phases once.

Resolves #3073
Resolves #3113
Resolves #3066
@dima-avdeev-jb dima-avdeev-jb requested review from pjBooms and removed request for igordmn July 11, 2023 19:34
@pjBooms
Copy link
Collaborator

pjBooms commented Jul 14, 2023

  • restructure sources in the way that resource management logic will be in a separate package

Copy link
Contributor

@dima-avdeev-jb dima-avdeev-jb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked in this branch: #3351
Thanks, it works!!!

@@ -5,7 +5,7 @@ kotlin.code.style=official
# __KOTLIN_COMPOSE_VERSION__
kotlin.version=1.8.20
# __LATEST_COMPOSE_RELEASE_VERSION__
compose.version=1.4.1
compose.version=0.0.0-dev1099
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to beta release version after release

@AlexeyTsvetkov AlexeyTsvetkov merged commit 16114b2 into master Jul 18, 2023
@AlexeyTsvetkov AlexeyTsvetkov deleted the ios-resources-sync branch July 18, 2023 17:11
j-roskopf added a commit to j-roskopf/SyncSphere that referenced this pull request Nov 15, 2023
followed JetBrains/compose-multiplatform#3340
manually removed all other referecnes to cocoapods + pods related build code
update ios run target in AS
j-roskopf added a commit to j-roskopf/SyncSphere that referenced this pull request Nov 15, 2023
followed JetBrains/compose-multiplatform#3340
manually removed all other referecnes to cocoapods + pods related build code
update ios run target in AS
j-roskopf added a commit to j-roskopf/SyncSphere that referenced this pull request Nov 15, 2023
followed JetBrains/compose-multiplatform#3340
manually removed all other referecnes to cocoapods + pods related build code
update ios run target in AS

Co-authored-by: Joe Roskopf <joseph.thomas.roskopf@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants