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

ERROR:: Unknown Directory structure, both java & kotlin files not found. #14

Closed
nbnD opened this issue Sep 22, 2021 · 10 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@nbnD
Copy link

nbnD commented Sep 22, 2021

Old Package Name: com.mithila.deliveryapp
Updating build.gradle File
Updating Main Manifest file
Updating Debug Manifest file
Updating Profile Manifest file

ERROR:: Unknown Directory structure, both java & kotlin files not found.

Get this log in terminal.

@RastislavMirek
Copy link

Same here, any ideas?

@atiqsamtia
Copy link
Owner

@RastislavMirek please do share your project directory structure for android dir.

@RastislavMirek
Copy link

just the standard, see the screenshot

Screen Shot 2021-11-11 at 11 36 55

@atiqsamtia
Copy link
Owner

can you share gradle.build file as well? in app dir

It seems like you updated the package ID in gradle.build manually and didn't change the directory structure of MainActivity.

@RastislavMirek
Copy link

Here it is. There is not package in that gradle, only application ID, which I thought is a different thing. In any case, if this is the problem then I highly suggest that the plugin either handles that gracefully or at least prints a correct error message, saying that "these 2 must match", not that "kotlin / java files not found".

def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 31

    defaultConfig {
        applicationId "sk.ariva.dev"
        minSdkVersion 23
        targetSdkVersion 31
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

@atiqsamtia
Copy link
Owner

Yes, that's the issue.

application-id is the package name. these two are the same things.

The package cannot handle that gracefully because it can lose changes someone has made to MainActivity class. Also, this is how the plugin finds the correct path to the file.
You are right about the error message. Let me change that to a meaningful message and push an update shortly.

I'll test other scenarios as well to handle the issue gracefully. I'll post the update here on this issue. I'm not closing the issue yet.

@atiqsamtia atiqsamtia added the bug Something isn't working label Nov 11, 2021
@atiqsamtia atiqsamtia self-assigned this Nov 11, 2021
@RastislavMirek
Copy link

Great, thank you. Yes, after changing it back to the original name matching the original package structure, the rename works.

A good error message will help a lot of people (even this discussion will help many). I understand the technical difficulties but if you want to improve user experience then ideally, when the new package name is the same as the name already changed in applicationId in gradle.build the rename should just "ignore" that (e.g. old name is "com.old.name", user is trying to rename it to "com.new.name" and applicationId is "com.new.name"). If it is yet another name (e.g. old name is "com.old.name", user is trying to rename it to "com.new.name" and applicationId is "com.yet.another") then a good error message should be displayed.

Just my 5 cents.

@yogithesymbian
Copy link

yogithesymbian commented Nov 25, 2021

i have solved by change the directory name where the MainActivity.kt is placed

for example

  1. first your package name is com.yogithesymbian
  2. then you need to change into id.co.yogi.yogithesymbian_admin
  3. run flutter pub run change_app_package_name:main id.co.yogi.yogithesymbian_admin

so if the error is appears, you just need create a new folder by name of your package

  1. before your path is /android/app/src/main/kotlin/com/yogithesymbian/MainActivity.kt
  2. change into /android/app/src/main/kotlin/id/co/yogi/yogithesymbian_admin/MainActivity.kt
  3. now try run against flutter pub run change_app_package_name:main id.co.yogi.yogithesymbian_admin

hope this help you

if you didnt change the folder name, you cant run on android ( i have waiting until 12 hours just waiting on installing ) , but i can run on IOS , so after i try above step , just 3 - 5 second my apps was installed .

@A-Eric-J
Copy link

this problem is solved for me by these steps:
for example my package name is com.example.eric and i want to change it to com.banana.eric (lol).
first run flutter pub run change_app_package_name:main com.banana.eric
as you know this error happens: Unknown Directory structure, both java & kotlin files not found.
this error is because of the directory of the MainActivity.kt, that you should change the directory to new directory:
previous directory: /android/app/src/main/kotlin/com/example/eric/MainActivity.kt
new directory: /android/app/src/main/kotlin/com/banana/eric/MainActivity.kt

the most important note is in MainActivity.kt that you have to notice:
at the first line of the MainActivity.kt, package name should be changed again if you don't change that line you'll have error in building although you can have release apk or bundle app.
change first line of MainActivity.kt :
package: com.example.eric => package: com.banana.eric
last step is running this command again:
flutter pub run change_app_package_name:main com.banana.eric
everything is ok right now. and you can build release apk or app bundle or running in debug mode with new package name.

@atiqsamtia
Copy link
Owner

Changed the mechanism and now it'll work fine irrespective of the directory structure. Fix is LIVE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants