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

Transfer of improvements to an existing project #5

Open
valery-lavrik opened this issue Jul 28, 2022 · 5 comments
Open

Transfer of improvements to an existing project #5

valery-lavrik opened this issue Jul 28, 2022 · 5 comments

Comments

@valery-lavrik
Copy link

Is it possible to make changes to an existing project, fix it to disable downsampling of the image. because it is very difficult to transfer the project to this assembly

@clytras
Copy link
Owner

clytras commented Jul 28, 2022

Yes it is possible, but it's not an easy task.
You have to clone and patch fresco by yourself and then make all needed modifications to make it compile and work.

@valery-lavrik
Copy link
Author

can I get more details?

@clytras
Copy link
Owner

clytras commented Jul 28, 2022

You can clone and patch Fresco using these commands:

"fresco-clone": "git clone https://github.com/facebook/fresco.git android/libraries/fresco && cd android/libraries/fresco && git checkout tags/v2.5.0",
"fresco-patch": "yarn file-patch ./patches/DecodeProducer.java.diff android/libraries/fresco/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DecodeProducer.java",
"fresco-setup": "yarn fresco-clone && yarn fresco-patch"

but for the patching, there has to be the correct patches/DecodeProducer.java.diff file to patch the cloned Fresco lib inside android/libraries/fresco/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DecodeProducer.java.
It's better to go and change it by hand, open the DecodeProducer.java file and comment the following lines inside the ProgressiveDecoder function:

public ProgressiveDecoder(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    final ProducerContext producerContext,
    final boolean decodeCancellationEnabled,
    final int maxBitmapSize) {
  super(consumer);
  mProducerContext = producerContext;
  mProducerListener = producerContext.getProducerListener();
  mImageDecodeOptions = producerContext.getImageRequest().getImageDecodeOptions();
  mIsFinished = false;
  JobRunnable job =
      new JobRunnable() {
        @Override
        public void run(EncodedImage encodedImage, @Status int status) {
          if (encodedImage != null) {
            mProducerContext.setExtra(
                ProducerContext.ExtraKeys.IMAGE_FORMAT,
                encodedImage.getImageFormat().getName());
            // if (mDownsampleEnabled || !statusHasFlag(status, Consumer.IS_RESIZING_DONE)) {
            //   ImageRequest request = producerContext.getImageRequest();
            //   if (mDownsampleEnabledForNetwork
            //       || !UriUtil.isNetworkUri(request.getSourceUri())) {
            //     encodedImage.setSampleSize(
            //         DownsampleUtil.determineSampleSize(
            //             request.getRotationOptions(),
            //             request.getResizeOptions(),
            //             encodedImage,
            //             maxBitmapSize));
            //   }
            // }

            // if (producerContext
            //     .getImagePipelineConfig()
            //     .getExperiments()
            //     .shouldDownsampleIfLargeBitmap()) {
            //   maybeIncreaseSampleSize(encodedImage);
            // }

            doDecode(encodedImage, status);
          }
        }
      };
  mJobScheduler = new JobScheduler(mExecutor, job, mImageDecodeOptions.minDecodeIntervalMs);
  mProducerContext.addCallbacks(
      new BaseProducerContextCallbacks() {
        @Override
        public void onIsIntermediateResultExpectedChanged() {
          if (mProducerContext.isIntermediateResultExpected()) {
            mJobScheduler.scheduleJob();
          }
        }

        @Override
        public void onCancellationRequested() {
          if (decodeCancellationEnabled) {
            handleCancellation();
          }
        }
      });
}

Then download and unzip/install Android NDK Revision 23 or the one that matches your RN version NDK.

Then create a file android/libraries/fresco/local.properties with the following contents:

ndk.dir=G:\\Dev\\Android\\android-ndk-r23b
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

Remember to change ndk.dir to the actual path that you've installed NDK R23b.

Inside android/settings.gradle add Fresco build like:

rootProject.name = 'HelloWorld'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
includeBuild ('libraries/fresco')
include ':app'

Inside android/build.gradle add "proguard-fresco.pro" at release/proguardFiles:

proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro", "proguard-fresco.pro"

And now, after sacrificing a cow and pray to the gods, try to build your app and see what happens!

Also, if you have a newer RN version, you might skip the direct NDK download and use Android Studio "NDK (Side by side)" install the proper NDK version, but I haven't tried that yet.

@valery-lavrik
Copy link
Author

@clytras thanks, it remains to find a cow ))

@ShonGamliel
Copy link

You can clone and patch Fresco using these commands:

"fresco-clone": "git clone https://github.com/facebook/fresco.git android/libraries/fresco && cd android/libraries/fresco && git checkout tags/v2.5.0",
"fresco-patch": "yarn file-patch ./patches/DecodeProducer.java.diff android/libraries/fresco/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DecodeProducer.java",
"fresco-setup": "yarn fresco-clone && yarn fresco-patch"

but for the patching, there has to be the correct patches/DecodeProducer.java.diff file to patch the cloned Fresco lib inside android/libraries/fresco/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DecodeProducer.java. It's better to go and change it by hand, open the DecodeProducer.java file and comment the following lines inside the ProgressiveDecoder function:

public ProgressiveDecoder(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    final ProducerContext producerContext,
    final boolean decodeCancellationEnabled,
    final int maxBitmapSize) {
  super(consumer);
  mProducerContext = producerContext;
  mProducerListener = producerContext.getProducerListener();
  mImageDecodeOptions = producerContext.getImageRequest().getImageDecodeOptions();
  mIsFinished = false;
  JobRunnable job =
      new JobRunnable() {
        @Override
        public void run(EncodedImage encodedImage, @Status int status) {
          if (encodedImage != null) {
            mProducerContext.setExtra(
                ProducerContext.ExtraKeys.IMAGE_FORMAT,
                encodedImage.getImageFormat().getName());
            // if (mDownsampleEnabled || !statusHasFlag(status, Consumer.IS_RESIZING_DONE)) {
            //   ImageRequest request = producerContext.getImageRequest();
            //   if (mDownsampleEnabledForNetwork
            //       || !UriUtil.isNetworkUri(request.getSourceUri())) {
            //     encodedImage.setSampleSize(
            //         DownsampleUtil.determineSampleSize(
            //             request.getRotationOptions(),
            //             request.getResizeOptions(),
            //             encodedImage,
            //             maxBitmapSize));
            //   }
            // }

            // if (producerContext
            //     .getImagePipelineConfig()
            //     .getExperiments()
            //     .shouldDownsampleIfLargeBitmap()) {
            //   maybeIncreaseSampleSize(encodedImage);
            // }

            doDecode(encodedImage, status);
          }
        }
      };
  mJobScheduler = new JobScheduler(mExecutor, job, mImageDecodeOptions.minDecodeIntervalMs);
  mProducerContext.addCallbacks(
      new BaseProducerContextCallbacks() {
        @Override
        public void onIsIntermediateResultExpectedChanged() {
          if (mProducerContext.isIntermediateResultExpected()) {
            mJobScheduler.scheduleJob();
          }
        }

        @Override
        public void onCancellationRequested() {
          if (decodeCancellationEnabled) {
            handleCancellation();
          }
        }
      });
}

Then download and unzip/install Android NDK Revision 23 or the one that matches your RN version NDK.

Then create a file android/libraries/fresco/local.properties with the following contents:

ndk.dir=G:\\Dev\\Android\\android-ndk-r23b
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

Remember to change ndk.dir to the actual path that you've installed NDK R23b.

Inside android/settings.gradle add Fresco build like:

rootProject.name = 'HelloWorld'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
includeBuild ('libraries/fresco')
include ':app'

Inside android/build.gradle add "proguard-fresco.pro" at release/proguardFiles:

proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro", "proguard-fresco.pro"

And now, after sacrificing a cow and pray to the gods, try to build your app and see what happens!

Also, if you have a newer RN version, you might skip the direct NDK download and use Android Studio "NDK (Side by side)" install the proper NDK version, but I haven't tried that yet.

hey, i have an issue, i opened a fresh react-native app and did all the steps, and the build is failing with this error:

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':fresco:animated-base'.

Failed to notify project evaluation listener.
org/gradle/api/plugins/MavenPlugin
Could not create task ':fresco:animated-base:androidJavadoc'.
> Could not create task of type 'AndroidJavadocs'.
> List is empty.

it happens after the step to add includeBuild ('libraries/fresco') in settings.gradle

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

No branches or pull requests

3 participants