Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Mpp sample #1494

Merged
merged 13 commits into from
May 28, 2018
Merged

Mpp sample #1494

merged 13 commits into from
May 28, 2018

Conversation

StefMa
Copy link
Contributor

@StefMa StefMa commented Apr 12, 2018

I've created a sample implementation from the Multiplatform doc.
Don't know if you are interested in it or not.
But I've just added it to the samples and refer it in the multiplatform doc.

Let me know if you want to use it (then I have to adjust the package names (guru.stefma to org.jetbrains) and stuff like that.
Otherwise feel free to just close it 😄

@@ -0,0 +1,172 @@
#!/usr/bin/env sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Better reuse shared gradlew in ../../.

Copy link
Contributor

Choose a reason for hiding this comment

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

Android Studio generates this wrapper while creating the project. I think it's better to not remove it because we have two separate builds in any case. The first one is the multiplatform library and is managed manually. The second one is the Android Studio build which compiles the Android app and is fully managed by Android Studio (including Gradle's version and its updates).

The Gradle guys also create a separate wrapper for each sample project in their samples (e.g. https://github.com/gradle/native-samples/tree/master/cpp/application)

@@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

@StefMa
Copy link
Contributor Author

StefMa commented Apr 13, 2018

@olonho I can' remove these two gradle wrapper files. But I can't remove the androidApp/gradle/ (since it is needed for Android Studio. Otherwise it will download Gradle 4.0 which isn't working with the Android Plugin 3.0+).
Having just the gradle dir inside but not the wrappers looks very strange (and not common) IMO.
I would keep it like it is.

Beside of that and I wanted to be as close as possible with the documentation. And there stands nothing to use the wrapper from the root dir in the android project.
If we really decided to use a architecture like that I would recommend that we update the documentation as well...?!

@StefMa StefMa force-pushed the mpp_sample branch 2 times, most recently from db2774d to 580275b Compare April 13, 2018 12:38
@StefMa
Copy link
Contributor Author

StefMa commented Apr 23, 2018

@olonho @ilmat192
Do you want to merge it?
Otherwise I would close it :D

@ilmat192
Copy link
Contributor

I think yes, adding such a sample makes sense. But I didn't check this PR on my machine yet so let me take a closer look at it first :)

@olonho What do you think about this MPP sample?

}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
Copy link

Choose a reason for hiding this comment

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

jre dependency is actually deprecated since 1.2.0 and you should use jdk:
http://kotlinlang.org/docs/reference/whatsnew12.html#kotlin-standard-library-artifacts-and-split-packages

jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
Copy link

Choose a reason for hiding this comment

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

3.1.2 is actually latest version

@ilmat192
Copy link
Contributor

Hi @StefMa!

I want to bring some improvements in the sample (in particular rewrite the framework building script as shown in #1583 and fix the remarks above). What is the best way to do it? May you give me access rights to push in this branch in you repo? Or it's better to create a separate branch in our repo and move your commits in it?

@StefMa
Copy link
Contributor Author

StefMa commented May 15, 2018

Hi @ilmat192

I've checked that little checkbox in this PR. So normally you have already push rights to this PR :)
bildschirmfoto 2018-05-15 um 13 17 06

See also this article and this one.

Feel free to checkout this branch and push anything you like :) 👍

@thevery
Copy link

thevery commented May 16, 2018

@ilmat192 @StefMa maybe add multiplatform tests as well?

@ilmat192
Copy link
Contributor

@StefMa I've rebased the sample onto master and added some new changes. Please look at them and, if all is ok, I'll merge the PR.

MULTIPLATFORM.md Outdated

Kotlin/Native requires Gradle 4.7 or higher so you need to make sure that the AS project uses the correct
Gradle version. To do this, open `androidApp/gradle/gradle-wrapper.properties` and check the `distributionUrl`
property. Fix it if it's necessary.
Copy link
Contributor Author

@StefMa StefMa May 23, 2018

Choose a reason for hiding this comment

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

Maybe:

Upgrade if necessary

sounds a little bit better.
But its just a minor. Keep it if you like :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'org.greeting:android:1.0'
implementation project(':greeting:android')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted this sample to reflect 100% of the documentation.
If we use this the documentation and the sample is not the same anymore.
Either change the docu or revert this...

Update

Just seen that there is a big note in the documentation 🙃
Maybe we don't "note" it anymore but used it as a general rule?!

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you upgraded via the wrapper task?
It's weird that the *jar haven't changed...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, just forgot about it. Thanks!

@@ -11,7 +11,7 @@ buildscript {
// Specify all the plugins used as dependencies
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.7-dev-1407"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:${project.property('konan.plugin.version')}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please update the documenation with somehting like $kotlinNativeGradlePluginVersion ...
Then it isn't hardcoded 👍

@@ -1,4 +1,9 @@
enableFeaturePreview('GRADLE_METADATA')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that needed for the sample?
Then we have to documented that as well

Copy link
Contributor

Choose a reason for hiding this comment

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

The sample in a separate repo uses KN 0.7 and there is no need to add this line for that version.

include ':greeting'
include ':greeting:common'
include ':greeting:android'
include ':greeting:ios'

includeBuild '../../shared'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would recommend to add a comment here that this is not part "of the sample" and only used for this sample...
Know what I mean? 🙃

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I see :)

The sample becomes a little bit complicated with all these composite builds.
May be it's better to move it in a separate repo?

We use composite build to allow a user to build all samples in the main repo with the compiler and the Gradle plugin built from sources right now. But in a separate repo we can use a fixed KN version and where will be no differences between the documentation and the sample itself. I can make a repo under JB organisation and move your changes into it. What do you think about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. The sample blows a little bit 🙃
Yes, I think it make sense to move it in a new repository.
The only thing we have to make sure is that the documentation and the new repo are always in sync.
We can also move the documentation into the new repository and link in this repo to the new repo?! 🤔
Having the documentation here but the implementation in a new repo is a little bit strange...

Anyway.
I would welcome to have a separate repository for it.
The rest can be discussed then 👍

Copy link
Contributor

@ilmat192 ilmat192 May 25, 2018

Choose a reason for hiding this comment

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

Having the documentation here but the implementation in a new repo is a little bit strange

Having all docs in one place is more convenient though. But you're right too and I would rather move the MPP doc in the new repo. @olonho what do you think?

@@ -0,0 +1,6 @@
.iml
Copy link

Choose a reason for hiding this comment

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

this one is not required

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.31'
Copy link

Choose a reason for hiding this comment

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

it 1.2.31 required? can we use latest 1.2.41?

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

// By default the project directory name is used as an artifact name thus the full dependency
// description will be 'org.greeting:android:1.0'
group = 'org.greeting'
version = 1.0
Copy link

Choose a reason for hiding this comment

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

maven-style dependency is actually not used in this sample anymore, only project dependency

Copy link
Contributor

Choose a reason for hiding this comment

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

We will use the maven-style dependency in a separate repo.


import XCTest
import Greeting
@testable import iosApp
Copy link

Choose a reason for hiding this comment

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

unused

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Copy link

Choose a reason for hiding this comment

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

since we don't have android app itself (only empty stub) is makes no sense to add extensions here

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be useful if a user wants to write an application on basis of this sample.

Copy link

Choose a reason for hiding this comment

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

AS will add this plugin automatically on creating new activity, but this is not a big deal anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, removed this.

compileSdkVersion 27
defaultConfig {
applicationId "org.konan.multiplatform"
minSdkVersion 24
Copy link

Choose a reason for hiding this comment

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

imho sample should use either 15 or 21

Copy link
Contributor

Choose a reason for hiding this comment

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

Done


dependencies {
// Set up compilation dependency on common Kotlin stdlib
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
Copy link

Choose a reason for hiding this comment

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

can we use implementation here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

The project has been moved in a separate repo.
@StefMa
Copy link
Contributor Author

StefMa commented May 28, 2018

If I could I would approve that PR 👍
Nice work. Thanks @ilmat192

@ilmat192
Copy link
Contributor

ilmat192 commented May 28, 2018

Thanks! The separate repo is here: https://github.com/JetBrains/kotlin-mpp-example. I've fixed all the remarks added to this PR there.

If there are no objections from others, I'll merge this PR.

CC @thevery @olonho

@thevery
Copy link

thevery commented May 28, 2018

Looks almost ok, but there are still some issues:

  1. android build is not working -
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> More than one file was found with OS independent path 'META-INF/main.kotlin_module'

Add

    packagingOptions {
        exclude 'META-INF/main.kotlin_module'
    }

to fix
2) Why still includeBuild in https://github.com/JetBrains/kotlin-mpp-example/blob/master/androidApp/settings.gradle?

@ilmat192
Copy link
Contributor

@thevery Thanks, I've fixed the issue with packaging.

  1. We add the Greeting build as an included one to allow resolving the Greeting library in the maven-like manner here.

@thevery
Copy link

thevery commented May 28, 2018

  1. ic
    LGTM

@ilmat192 ilmat192 merged commit 705e39a into JetBrains:master May 28, 2018
SvyatoslavScherbina pushed a commit that referenced this pull request Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants