Skip to content

Commit 75101a0

Browse files
authoredAug 25, 2022
Merge pull request #1 from buijs-dev/develop
Develop
2 parents c594dcf + 485d53b commit 75101a0

36 files changed

+903
-809
lines changed
 

‎CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 0.2.0
2+
* Uses Klutter Gradle v2022.r6-8.alpha.
3+
* New project template uses Klutter DSL to apply Klutter dependencies.
4+
* Flutter generated files are removed from lib folder after klutter init.
5+
* Moved task klutterInstallPlatform from generated build.gradle.kts to Gradle plugin.
6+
* Renamed task klutterInstallPlatfrom to klutterBuild.
7+
* Moved task klutterCopyAarFile from generated build.gradle.kts to Gradle plugin.
8+
* Moved task klutterIosFramework from generated build.gradle.kts to Gradle plugin.
9+
* Changed platform build.gradle.kts to create an XCFramework instead of fat framework for iOS.
10+
* [Bugfix](https://github.com/buijs-dev/klutter/issues/4) App does not work on Mac M1.
11+
112
## 0.1.3
213
* Uses Klutter Gradle v2022.r6-7.alpha.
314

‎README.md

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[<img src="https://github.com/buijs-dev/klutter-dart/blob/main/logo_animated.gif?raw=true" width="300" alt="buijs software logo" />](https://github.com/buijs-dev)
2-
3-
# Klutter
41
[![GitHub license](https://img.shields.io/github/license/buijs-dev/klutter-dart?color=black&logoColor=black&style=for-the-badge)](https://github.com/buijs-dev/klutter-dart/blob/main/LICENSE)
52
[![pub](https://img.shields.io/pub/v/klutter?style=for-the-badge)](https://pub.dev/packages/klutter)
63
[![codecov](https://img.shields.io/codecov/c/github/buijs-dev/klutter-dart?logo=codecov&style=for-the-badge)](https://codecov.io/gh/buijs-dev/klutter-dart)
74
[![CodeScene Code Health](https://img.shields.io/badge/CODESCENE-10-brightgreen?style=for-the-badge)](https://codescene.io/projects/27237)
85

6+
<br>
7+
8+
<img src="https://github.com/buijs-dev/klutter/blob/develop/.github/assets/metadata/icon/klutter_logo.png?raw=true" alt="buijs software logo" />
9+
910
The Klutter Framework makes it possible to write a Flutter plugin for both Android
1011
and iOS using [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html).
1112
Instead of writing platform specific code twice in 2 languages (Swift + Kotlin),
@@ -24,12 +25,13 @@ Use this plugin if you want to:
2425
1. [Installation](#Installation)
2526
2. [Using plugins](#Usage)
2627
3. [Creating plugins](#Creation)
28+
4. [FAQ!](#Faq!)
2729

2830
For a step-by-step guide, see the battery app with Klutter [tutorial](https://buijs.dev/klutter-2/).
2931

3032
# Installation
3133
<b>What's the point?</b></br>
32-
Plugins build with the Klutter Framework work slightly different than regular plugins.
34+
Plugins build with the Klutter Framework work slightly different from regular plugins.
3335
The Klutter dependency is a requirement for both using and creating plugins with Klutter.
3436

3537
<b>Steps:</b></br>
@@ -48,14 +50,14 @@ flutter pub get
4850

4951
# Usage
5052
<b>What's the point?</b></br>
51-
Plugins build with the Klutter Framework work slightly different than regular plugins.
53+
Plugins build with the Klutter Framework work slightly different from regular plugins.
5254
The following tasks help Flutter to locate Klutter plugins
5355
and ensure compatibility between Flutter Android/IOS configuration and Klutter plugin Android/IOS configuration.
5456

5557
<b>Steps:</b></br>
5658
1. Installation.
57-
3. Initialization.
58-
4. Add dependencies.
59+
2. Initialization.
60+
3. Add dependencies.
5961

6062
Install Klutter as dependency as described [here](#Installation).
6163

@@ -65,8 +67,8 @@ Initialize Klutter in your project by running:
6567
flutter pub run klutter:consumer init
6668
```
6769

68-
The init task will setup Klutter for both Android and iOS.
69-
Alternatively you can setup Android and IOS separately.
70+
The init task will set up Klutter for both Android and iOS.
71+
Alternatively you can set up Android and IOS separately.
7072

7173
Setup Android by running:
7274

@@ -80,7 +82,7 @@ Setup IOS by running:
8082
flutter pub run klutter:consumer init=ios
8183
```
8284

83-
Finally Klutter plugins can be added by running the add command.
85+
Finally, Klutter plugins can be added by running the add command.
8486

8587
<B>Example</B>:</br> Add the library 'awesome_plugin' to your project:
8688

@@ -174,4 +176,34 @@ flutter pub run klutter:producer install=library
174176
```
175177

176178
Now test the plugin by following the steps outlined [here](#Usage) in the root/example project.
177-
When done you can run the example project from the root/example/lib folder and see your first plugin in action!
179+
When done you can run the example project from the root/example/lib folder and see your first plugin in action!
180+
181+
# Faq!
182+
1. [App won't start on...](#App%20won't%20start)
183+
184+
## App won't start
185+
186+
Make sure you have followed all the following steps:
187+
- flutter create <your_plugin_name> --org <your_organisation> --template=plugin --platforms=android,ios.
188+
- [klutter](https://pub.dev/packages/klutter) is added to the dependencies in your pubspec.yaml
189+
(both the plugin and plugin/example for testing).
190+
- do flutter pub get in both root and root/example folder.
191+
- do flutter pub run klutter:producer init in the root folder.
192+
- do flutter pub run klutter:producer install=library in the root folder.
193+
- do flutter pub run klutter:producer install=platform in the root folder.
194+
- do flutter pub run klutter:consumer init in the root/example folder.
195+
- do flutter pub run klutter:consumer add=<your_plugin_name> in the root/example folder.
196+
197+
### For Android emulator:
198+
There should be a .klutter-plugins file in the root/example folder containing an entry for your plugin.
199+
If not then do flutter pub run klutter:consumer add=<your_plugin_name> in the root/example folder again.
200+
201+
There should be a platform.aar file in the root/android/klutter folder. If not then do flutter pub run
202+
klutter:producer install=platform from the root folder.
203+
204+
### For iOS simulator:
205+
There should be a Platform.xcframework folder in root/ios/Klutter. If not then do flutter pub run
206+
klutter:producer install=platform from the root folder.
207+
208+
If there's an error message saying unable to find plugin or similar then run pod update in the root/example/ios
209+
folder.

‎bin/consumer.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ import "package:klutter/klutter.dart";
2929
Future<void> main(List<String> args) async {
3030
print("""
3131
════════════════════════════════════════════
32-
KLUTTER (v0.1.3)
32+
KLUTTER (v$klutterPubVersion)
3333
════════════════════════════════════════════
3434
"""
3535
.ok);
3636

37+
print("This might take a while. Just a moment please...".boring);
38+
3739
final pathToRoot = Directory.current.absolutePath;
3840
final result = await execute(
3941
script: ScriptName.consumer,

‎bin/producer.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ import "package:klutter/klutter.dart";
2929
Future<void> main(List<String> args) async {
3030
print("""
3131
════════════════════════════════════════════
32-
KLUTTER (v0.1.3)
32+
KLUTTER (v$klutterPubVersion)
3333
════════════════════════════════════════════
3434
"""
3535
.ok);
3636

37+
print("This might take a while. Just a moment please...".boring);
38+
3739
final pathToRoot = Directory.current.absolutePath;
3840
final result = await execute(
3941
script: ScriptName.producer,

‎example/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
[<img src="https://github.com/buijs-dev/klutter-dart/blob/main/logo_animated.gif?raw=true" width="300" alt="buijs software logo" />](https://github.com/buijs-dev)
1+
<br />
2+
<img src="https://github.com/buijs-dev/klutter/blob/develop/.github/assets/metadata/icon/klutter_logo.png?raw=true" alt="buijs software logo" />
23

34
- For installation instructions see [here](./../README.md).
45
- For a step-by-step guide, see the battery app with Klutter [tutorial](https://buijs.dev/klutter-2/).

‎lib/res/gradle.properties

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ kotlin.code.style=official
88
android.useAndroidX=true
99

1010
#MPP
11-
kotlin.mpp.enableGranularSourceSetsMetadata=true
12-
kotlin.native.enableDependencyPropagation=false
13-
kotlin.mpp.enableCInteropCommonization=true
11+
kotlin.mpp.enableCInteropCommonization=true
12+
kotlin.mpp.stability.nowarn=true

‎lib/src/cli/cli.dart

+3
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,7 @@ extension ColoredMessage on String {
127127

128128
/// Log a red colored message.
129129
String get nok => "\x1B[31m${this}";
130+
131+
/// Default color (mostly whit(e/ish)).
132+
String get boring => "\x1B[49m${this}";
130133
}

‎lib/src/cli/command.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Command {
5252
}) {
5353
/// Regex to parse the CLI arguments.
5454
final taskRegex = RegExp(
55-
r"^\s*(init|add|install)\s*=*\s*([^\s]+|$)",
55+
r"^\s*(init|add|install)\s*=*\s*(\S+|$)",
5656
);
5757

5858
final match = taskRegex.firstMatch(task);

‎lib/src/cli/task_producer_init.dart

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21+
import "dart:io";
22+
2123
import "../common/project.dart";
2224
import "../common/utilities.dart";
2325
import "../producer/android.dart";
@@ -46,6 +48,12 @@ class ProducerInit extends Task {
4648

4749
extension on String {
4850
void get setupRoot {
51+
Directory("${this}/lib".normalize)
52+
// Delete folder and all children if they exist.
53+
..normalizeToFolder.maybeDelete
54+
// Create a new empty lib folder.
55+
..maybeCreate;
56+
4957
final name = findPluginName(this);
5058
writeGradleProperties(this);
5159

‎lib/src/cli/task_producer_install.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void _installPlatform(String pathToRoot) {
9696

9797
final result = Process.runSync(
9898
"./gradlew",
99-
["klutterInstallPlatform"],
99+
["klutterBuild"],
100100
workingDirectory: pathToRoot,
101101
environment: {"ANDROID_SDK_ROOT": androidSdkLocation},
102102
);

‎lib/src/common/config.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
/// The version of the Klutter Pub Plugin.
2+
const klutterPubVersion = "0.2.0";
3+
14
/// The version of the Klutter Gradle Plugin.
2-
const klutterGradleVersion = "2022.r6-7.alpha";
5+
const klutterGradleVersion = "2022.r6-8.alpha";
36

47
/// The minimum SDK version for Android.
58
const androidMinSdk = 21;

‎lib/src/common/utilities.dart

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ extension FileUtil on FileSystemEntity {
5555
return this;
5656
}
5757

58+
/// Check if the Directory exists and then delete it.
59+
FileSystemEntity get maybeDelete {
60+
if (existsSync()) {
61+
deleteSync(recursive: true);
62+
}
63+
return this;
64+
}
65+
5866
/// Return absolute path of current File or Folder as String.
5967
String get absolutePath => absolute.path;
6068

‎lib/src/consumer/ios.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ void excludeArm64FromPodfile(String pathToIos) =>
5959

6060
extension on String {
6161
/// Return File path to the ios/Podfile.
62-
File get toPodfile => File("${this}/Podfile".normalize)
63-
..ifNotExists((folder) =>
64-
throw KlutterException("Missing Podfile in folder: ${this}"));
62+
File get toPodfile {
63+
return File("${this}/Podfile".normalize);
64+
}
6565
}
6666

6767
extension on File {
@@ -70,6 +70,10 @@ extension on File {
7070
///
7171
/// Without doing this the app won't start on a simulator.
7272
void get writeExclusionLines {
73+
if (!existsSync()) {
74+
return;
75+
}
76+
7377
// Used to check if adding exclusion lines is done.
7478
var hasAdded = false;
7579

‎lib/src/producer/android.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class _Configuration {
194194
| dependencies {
195195
| classpath 'com.android.tools.build:gradle:7.0.4'
196196
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
197-
| classpath "dev.buijs.klutter:core:$klutterGradleVersion"
197+
| classpath "dev.buijs.klutter:kore:$klutterGradleVersion"
198198
| }
199199
|}
200200
|
@@ -233,7 +233,7 @@ class _Configuration {
233233
|dependencies {
234234
| runtimeOnly "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2"
235235
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10"
236-
| implementation "dev.buijs.klutter:core:$klutterGradleVersion"
236+
| implementation "dev.buijs.klutter:kore:$klutterGradleVersion"
237237
| implementation project(":klutter:${packageName.substring(1 + packageName.lastIndexOf("."))}")
238238
|}
239239
|

‎lib/src/producer/ios.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extension on File {
8888
// This is done so the line is added at a fixed point in the podspec.
8989
if (line.replaceAll(" ", "").contains("$prefix.dependency'Flutter'")) {
9090
newLines.add(
91-
""" $prefix.ios.vendored_frameworks = "Klutter/Platform.framework" """,
91+
""" $prefix.ios.vendored_frameworks = "Klutter/Platform.xcframework" """,
9292
);
9393

9494
hasAdded = true;

0 commit comments

Comments
 (0)
Please sign in to comment.